Jump to content

Mysql_fetch_array problems


Drezard

Recommended Posts

Is there anything wrong with this? as in code wise?

 

The mysql_fetch_array() is failing.

 

Code:

 

$query = "SELECT * FROM user_profiles WHERE user_id='$user_id'";

$result = mysql_query($query);

$array = mysql_fetch_array($result);

$name = $array[1];

$email = $array[2]; 	

$location = $array[3];	

 

Daniel

Link to comment
https://forums.phpfreaks.com/topic/104994-mysql_fetch_array-problems/
Share on other sites

Is there anything wrong with this? as in code wise?

 

The mysql_fetch_array() is failing.

 

Code:

 

$query = "SELECT * FROM user_profiles WHERE user_id='$user_id'";

$result = mysql_query($query);

$array = mysql_fetch_array($result);

$name = $array[1];

$email = $array[2]; 	

$location = $array[3];	

 

Daniel

 

With the Array you need to use:

$name = $array['Name']; (or whatever field name it is)

$email = $array['Email'];

$location = $array['Location'];

 

BTW with an array it would actually start at 0 instead of 1, so 0,1,2 not 1,2,3.

<?php

$a=mysql_query("SELECT `name`,`email`,`location` FROM `user_profiles` WHERE `user_id` = '$user_id'");
$b=mysql_fetch_assoc($a) or mysql_error();

echo 'Name: '.$b['name'].'<br />';
echo 'Email: '.$b['email'].'<br />';
echo 'Location: '.$b['location'];

?>

 

thats how id do it...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.