Jump to content

[SOLVED] How to echo an Array


ManicMax

Recommended Posts

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

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

<?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 ;)

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.