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

Link to comment
Share on other sites

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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.