i am having trouble displaying my database table...i am new to php and mysql (just started last week)... this is the code iam using:

<?php

//connect
mysql_connect("","","") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

//query the db
$getnews = mysql_query("SELECT * FROM shows ORDER BY id DESC") or die(mysql_error());

while ($row = mysql_fetch_assoc($getnews))
{


 //get data
$id = $row['id'];
$venue = $row['venue'];
$date = date("m/d/Y", strtotime($row[date]));
$city = $row['city'];
$state = $row['state'];
$exceptions = $row['exceptions'];
$countries = $row['countries'];


echo "&theDates=$date|&theStates=$state|&theCities=$city|&theExceptions=$exceptions|&theClubs=$venue|&theIDs=$id|&theCountries=$countries|
<br>";




				 
}
?>

but it is display it like this on the browser:
&theDates=date01|&theStates=state01|&theCities=city01|theExceptions=exceptions01|&theClubs=club01|&theIDs=id01|&theCountries=countries01|

&theDates=date02|&theStates=state02|&theCities=city02|theExceptions=exceptions02|&theClubs=club02|&theIDs=id02|&theCountries=countries02|


I need it to display like this:

&theDates=date01|date02|&theStates=state01|state02|&theCities=city01|city02|theExceptions=exceptions01|exceptions02|&theClubs=club01|club02|&theIDs=id01|id02|&theCountries=countries01|countries02|


so that one the php calls up the information from the database it is displayed in the corresponding area not each row seperatly...can anyone help me with this problem.....?

D

I didn't test it, but this should work just fine

<?php

//connect
mysql_connect("","","") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

//query the db
$getnews = mysql_query("SELECT * FROM shows ORDER BY id DESC") or die(mysql_error());
$id = array();
$venue = array();
$date = array();
$city = array();
$state = array();
$exceptions = array();
$countries = array();

while ($row = mysql_fetch_assoc($getnews))
{
 //get data
$id[] = $row['id'];
$venue[] = $row['venue'];
$date[] = date("m/d/Y", strtotime($row[date]));
$city[] = $row['city'];
$state[] = $row['state'];
$exceptions[] = $row['exceptions'];
$countries[] = $row['countries'];
}

echo "&theDates=".implode('|',$date)."|&theStates=".implode('|',$states)."|&theCities=".implode('|',$city)."|&theExceptions=".
    implode('|',$exceptions)."|&theClubs=".implode('|',$venue)."|&theIDs=".
    implode('|',$id)."|&theCountries=".implode('|',$countries)."|<br>";

?>

differences between yours and mine.


I initialize the variables as arrays.

Fill in the arrays with your sql result

then "implode" the array into a string separated with your required pipe symbol

I didn't test it, but this should work just fine

<?php

//connect
mysql_connect("","","") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

//query the db
$getnews = mysql_query("SELECT * FROM shows ORDER BY id DESC") or die(mysql_error());
$id = array();
$venue = array();
$date = array();
$city = array();
$state = array();
$exceptions = array();
$countries = array();

while ($row = mysql_fetch_assoc($getnews))
{
 //get data
$id[] = $row['id'];
$venue[] = $row['venue'];
$date[] = date("m/d/Y", strtotime($row[date]));
$city[] = $row['city'];
$state[] = $row['state'];
$exceptions[] = $row['exceptions'];
$countries[] = $row['countries'];
}

echo "&theDates=".implode('|',$date)."|&theStates=".implode('|',$states)."|&theCities=".implode('|',$city)."|&theExceptions=".
    implode('|',$exceptions)."|&theClubs=".implode('|',$venue)."|&theIDs=".
    implode('|',$id)."|&theCountries=".implode('|',$countries)."|<br>";

?>

differences between yours and mine.


I initialize the variables as arrays.

Fill in the arrays with your sql result

then "implode" the array into a string separated with your required pipe symbol

cool thanks just before your post i used a very long way to query the database for each column your way is much easier...and doesnt take to much space...thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.