Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HELP - mysql_fetch_array

0 views
Skip to first unread message

james

unread,
Jun 17, 2004, 4:01:33 PM6/17/04
to
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

Michael Austin

unread,
Jun 17, 2004, 4:27:41 PM6/17/04
to


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.

Marian Heddesheimer

unread,
Jun 17, 2004, 4:28:50 PM6/17/04
to
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/

james

unread,
Jun 17, 2004, 10:07:29 PM6/17/04
to
Marian Heddesheimer <170604....@spamgourmet.com> wrote in message news:<vkv3d056m1nvh80ic...@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?

james

unread,
Jun 17, 2004, 10:07:31 PM6/17/04
to
Marian Heddesheimer <170604....@spamgourmet.com> wrote in message news:<vkv3d056m1nvh80ic...@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!

Douglas Abernathy

unread,
Jun 17, 2004, 11:51:50 PM6/17/04
to

"james" <ja...@diroddi.com> wrote in message
news:15cff93e.04061...@posting.google.com...

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

0 new messages