0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by xGxTxEx
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.