By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

HELP - mysql_fetch_array

P: n/a
I am new to PHP and am trying to run a simple query and display the
result, with no luck. Here is the code I am using.

<?php

//start session
session_start();

//store cmpid from querystring
$_SESSION['session_cmpid'] = $_GET['cmpid'];
$campaign=$_SESSION['session_cmpid'];

//connect to db server
require dirname(__FILE__).'/core/dbconnect_vps.php';

//select db
$database = "atdata";

//define sql
$sql_campaignredirect = "SELECT web_confirmurl
FROM tbl_marketingcampaign
WHERE marketingcampaignid = '$campaign'";

//run sql
$result = mysql_db_query($database,$sql_campaignredirect)
or die (mysql_error());

//fetch data
$campaign_url = mysql_fetch_array($result);

//display data
echo 'URL is '.$campaign_url;

?>

Instead of displaying the data (http://www.domain.com), it returns:

URL is Array
I know it's probably a simple oversigt on my part but can't seem to
figure it out.

Thanks..........James
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
james wrote:
I am new to PHP and am trying to run a simple query and display the
result, with no luck. Here is the code I am using.

<?php

//start session
session_start();

//store cmpid from querystring
$_SESSION['session_cmpid'] = $_GET['cmpid'];
$campaign=$_SESSION['session_cmpid'];

//connect to db server
require dirname(__FILE__).'/core/dbconnect_vps.php';

//select db
$database = "atdata";

//define sql
$sql_campaignredirect = "SELECT web_confirmurl
FROM tbl_marketingcampaign
WHERE marketingcampaignid = '$campaign'";

//run sql
$result = mysql_db_query($database,$sql_campaignredirect)
or die (mysql_error());

//fetch data
$campaign_url = mysql_fetch_array($result);

//display data
echo 'URL is '.$campaign_url;

?>

Instead of displaying the data (http://www.domain.com), it returns:

URL is Array
I know it's probably a simple oversigt on my part but can't seem to
figure it out.

Thanks..........James

Looking at this might help:

$link = mysql_connect('gonzo', $USR);
if( $link ) {
mysql_select_db( $DB, $link );
if( $sql ) {
$sql = ereg_replace( ";$", "", $sql );
$sql = ereg_replace( "\\\\", "", $sql );
$result = mysql_query( $sql, $link );
if( $result ) {
echo( "<p>Results: for '$sql;'.</p>\n" );
if( $num = mysql_num_rows( $result ) ) {
echo( "<pre>\n" );
while( $array = mysql_fetch_row( $result ) ) {
while( list($key, $val) = each( $array ) ) {
echo "$val | ";
} # end while
}

Michael.
Jul 17 '05 #2

P: n/a
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
Instead of displaying the data (http://www.domain.com), it returns:

URL is Array


that's correct $campaign_url is an array because mysql_fetch_array()
returns an array ;-)

try this:
echo 'URL is '.$campaign_url['web_confirmurl'];

Regards

Marian

--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
Jul 17 '05 #3

P: n/a
Marian Heddesheimer <17*************@spamgourmet.com> wrote in message news:<vk********************************@4ax.com>. ..
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
Instead of displaying the data (http://www.domain.com), it returns:

URL is Array


that's correct $campaign_url is an array because mysql_fetch_array()
returns an array ;-)

try this:
echo 'URL is '.$campaign_url['web_confirmurl'];

Regards

Marian


I understand now. Thanks!

Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?
Jul 17 '05 #4

P: n/a
Marian Heddesheimer <17*************@spamgourmet.com> wrote in message news:<vk********************************@4ax.com>. ..
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
Instead of displaying the data (http://www.domain.com), it returns:

URL is Array


that's correct $campaign_url is an array because mysql_fetch_array()
returns an array ;-)

try this:
echo 'URL is '.$campaign_url['web_confirmurl'];

Regards

Marian


I understand now. Thanks!

Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?
Jul 17 '05 #5

P: n/a

"james" <ja***@diroddi.com> wrote in message
news:15**************************@posting.google.c om...
Marian Heddesheimer <17*************@spamgourmet.com> wrote in message

news:<vk********************************@4ax.com>. ..
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
Instead of displaying the data (http://www.domain.com), it returns:

URL is Array


that's correct $campaign_url is an array because mysql_fetch_array()
returns an array ;-)

try this:
echo 'URL is '.$campaign_url['web_confirmurl'];

Regards

Marian


I understand now. Thanks!

Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?


I prefer to use mysql_fetch_assoc() because you get ONLY the associative
indices. If you use mysql_fetch_array() you get the associative indices, but
you also get their numeric equivalents, for example:

//Suppose the query returned the following database items: user_id,
username, password
$query_string = "SELECT * FROM tbl_login";
$result=mysql_query($query_string);
while ($row=mysql_fetch_array($result)) {
//Do something with $row['user_id'], $row['username'], $row['password']
}

But in the above example code, $row[0] also equals $row['user_id'], $row[1]
equals $row['username'], etc.

It doesn't affect you for a simple example like this, but sometimes I have
needed to loop through all of the elements in $row using a foreach
statement, and the numeric indices messed me up.

Just a thought...

Douglas Abernathy

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.