ManicMax Posted April 19, 2008 Share Posted April 19, 2008 I want to define what exact variable to echo but my attempts so far have failed. My code is below but it just will not echo. echo "$row[" . $times[0] . "]"; Link to comment https://forums.phpfreaks.com/topic/101845-solved-how-to-echo-an-array/ Share on other sites More sharing options...
chigley Posted April 19, 2008 Share Posted April 19, 2008 echo $row[times][0]; ^ Try that? Or post your array structure if that doesn't work. Link to comment https://forums.phpfreaks.com/topic/101845-solved-how-to-echo-an-array/#findComment-521209 Share on other sites More sharing options...
ManicMax Posted April 19, 2008 Author Share Posted April 19, 2008 Here is how the time structure is made up: $times[0]='am700'; $times[1]='am730'; $times[2]='am800'; $times[3]='am830'; $times[4]='am900'; $times[5]='am930'; What I'm trying to do is query a database then echo a result from a particular field. The $times array is the field names and $row is the mysql_fetch_array() variable. I want to combine then like i tried. I need to put the $times variable into the [] of the $row array Link to comment https://forums.phpfreaks.com/topic/101845-solved-how-to-echo-an-array/#findComment-521212 Share on other sites More sharing options...
chigley Posted April 19, 2008 Share Posted April 19, 2008 You'll have to explain a bit better - I don't really understand you! Link to comment https://forums.phpfreaks.com/topic/101845-solved-how-to-echo-an-array/#findComment-521221 Share on other sites More sharing options...
ManicMax Posted April 19, 2008 Author Share Posted April 19, 2008 ok well i have the array times this contains the field names of the fields in my databse. $times[0]='am700'; $times[1]='am730'; $times[2]='am800'; $times[3]='am830'; $times[4]='am900'; $times[5]='am930'; A mysql query is run selects one row and all of the fields. I then want to echo certain ones depending on the script. What I need to do is put which every varaible from the times array is picked into the $row[HERE ]. So at the moment it comes out looking like echo $row[$times[1]]; Along those lines Link to comment https://forums.phpfreaks.com/topic/101845-solved-how-to-echo-an-array/#findComment-521229 Share on other sites More sharing options...
chigley Posted April 19, 2008 Share Posted April 19, 2008 <?php $times = array('am700', 'am730', 'am800', 'am830', 'am900', 'am930'); include("db.php"); $query = mysql_query("SELECT * FROM table_name") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); echo $row[$times[0]]; ?> ^ Try that Link to comment https://forums.phpfreaks.com/topic/101845-solved-how-to-echo-an-array/#findComment-521233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.