renojim Posted September 24, 2006 Share Posted September 24, 2006 Not new to programming, but an infant in PHP. I'm using the following code to get a value from a mySql table. The table has seven columns, one row, field Ronum is mediumint with a value of 1 in it and is the primary key. The following code runs fine, but when I get to the echo row/ronum at the bottom, $row contains only "ARRAY", and $ronum is blank. Don't get it.:<?php $user="root"; $host="localhost"; $password=""; $database = "Vshop"; $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection) or die ("Couldn't select database"); { $query = "Select Ronum From ro"; } $result = mysql_query($query) or die ("Couldn't execute query."); $row = mysql_fetch_array($result,MYSQL_NUM); extract ($row); echo "$row"; echo "$ronum";?> Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/21873-newbie-trouble-getting-data-from-database/ Share on other sites More sharing options...
.josh Posted September 24, 2006 Share Posted September 24, 2006 $row is an array of your data, with the field names as array elements. extracting $row will create variables having the same name as your field names. do this loop to see what is actually being retrieved, and then you will see what variables are being extracted.foreach ($row as $key => $val) { echo "key: $key value: $val <br>";}the "key" is the variable names that extract should build. Quote Link to comment https://forums.phpfreaks.com/topic/21873-newbie-trouble-getting-data-from-database/#findComment-97688 Share on other sites More sharing options...
sanfly Posted September 24, 2006 Share Posted September 24, 2006 I havent used the extract() function before, but from what I just read, $row should echo Array.However for the $ronum, should the key name be case sensitive? ie: $Ronum? Quote Link to comment https://forums.phpfreaks.com/topic/21873-newbie-trouble-getting-data-from-database/#findComment-97691 Share on other sites More sharing options...
xyn Posted September 24, 2006 Share Posted September 24, 2006 Replace... $row = mysql_fetch_array($result,MYSQL_NUM); extract ($row); echo "$row"; echo "$ronum";With...while( $data = mysql_fetch_array($result,MYSQL_NUM)){echo $data[0];} Quote Link to comment https://forums.phpfreaks.com/topic/21873-newbie-trouble-getting-data-from-database/#findComment-97698 Share on other sites More sharing options...
renojim Posted September 25, 2006 Author Share Posted September 25, 2006 Thanks all for getting me straightened out - great responses. I'm beginning to get a clue. Quote Link to comment https://forums.phpfreaks.com/topic/21873-newbie-trouble-getting-data-from-database/#findComment-97955 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.