Current location: Hot Scripts Forums » Programming Languages » PHP » PHP and Mysql Query


PHP and Mysql Query

Reply
  #1 (permalink)  
Old 12-03-03, 06:15 PM
ivan's Avatar
ivan ivan is offline
Newbie Coder
 
Join Date: Jul 2003
Location: malang-indonesia
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
PHP and Mysql Query

dear all,
example : i have a table in mysql
city table
-----------
id city_name
1 new york
2 paris
3 roma
4 baghdad
5 madrid
6 others

I want preview in browser (with PHP script ) like this :
new york paris roma
baghdad madrid others
........ ........

Can you give me the script ?

regards,
ivan
__________________
irfani_f@yahoo.com
irfani.ptmunibraw.org
Reply With Quote
  #2 (permalink)  
Old 12-04-03, 03:22 AM
fyrestrtr fyrestrtr is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
After you have successfully connected to the database
PHP Code:

$query "SELECT city_name FROM city_table";

if(!(
$result mysql_query($query)))
{
   die(
mysql_errno()." : ".mysql_error());
}
while (
$row mysql_fetch_assoc($query))
{
   echo 
$row['city_name'];

Reply With Quote
  #3 (permalink)  
Old 12-04-03, 04:10 AM
ivan's Avatar
ivan ivan is offline
Newbie Coder
 
Join Date: Jul 2003
Location: malang-indonesia
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
PHP and Mysql Query

thank you,but if your script run in browser :

$query = "SELECT city_name FROM city_table";
if(!($result = mysql_query($query)))
{
die(mysql_errno()." : ".mysql_error());
}
while ($row = mysql_fetch_assoc($query))
{
echo $row['city_name'];
}


result in browser :
newyork paris roma baghdad madrid others

i want this preview :

newyork | paris | roma
baghdad | madrid | others
others | others |

3 or 4 or 5 column preview (like photo galery)

regards,
ivan
__________________
irfani_f@yahoo.com
irfani.ptmunibraw.org
Reply With Quote
  #4 (permalink)  
Old 12-04-03, 05:00 AM
fyrestrtr fyrestrtr is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
add a counter, then mod it by the number of columns. If the result of the mod operation is 0, then echo out a <br />

Something like this (modify it for you own needs)
PHP Code:

$count 1;

$num_cols 3;
while(
$row mysql_fetch_assoc($query))
{
   echo 
$row['city_name']." | ";
   
$count++;
   if (
$count $num_cols == 0)
   {
      echo 
"<br />";
   }

Reply With Quote
  #5 (permalink)  
Old 12-08-03, 10:49 PM
ivan's Avatar
ivan ivan is offline
Newbie Coder
 
Join Date: Jul 2003
Location: malang-indonesia
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Work fine

thank you,
your script work fine
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 03:31 AM
PHP And MYSQL Developer Needed CarBoffin PHP 2 10-13-03 03:31 AM
MySQL with PHP question. HELP for a newbie kenfused PHP 3 08-02-03 12:53 AM
Free PHP, Perl and possible mySQL hosting! toby General Advertisements 8 06-17-03 01:04 AM


All times are GMT -5. The time now is 06:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.