Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Retrieving data from a database, and formatting all rows.Hel

Codes here !

Moderators: macek, egami, gesf

Retrieving data from a database, and formatting all rows.Hel

Postby nindoja » Mon Mar 24, 2003 12:42 pm

Hello, how can I retrieve data from a database, and format all rows to look the same??? I.E. TABLE assembly games. retrieve title, author, description, picture(s), and .zip file name. Take that data, and format it to look like this:


Code: Select all
Title here- Author here
description | picture
.zip file name(made into an html link).
nindoja
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Jan 08, 2003 4:45 pm

Postby quelle » Mon Mar 24, 2003 10:08 pm

There are many ways to format the data (for example you could display the results in a table).. it is up to you so here is some code to get you started:
Code: Select all
<?
   // connect to server
   $server = "localhost";
   $username = "";  // FILL IN
   $password = "";  // FILL IN
   $DBName = "";    // FILL IN
   
   $dbh = mysql_connect($server, $username, $password) or die("Error connecting to MySQL: ".mysql_error());
   mysql_select_db($DBName) or die("Error selecting DB: ".mysql_error());

   // perform query
   $query = "SELECT title, author, description, picture, zipname FROM $DBName";
   $result = mysql_query($query) or die("Error:" .mysql_error());

   // retrive values
   while ($row = mysql_fetch_array($result)) {
      $title = $row[0];
      $author = $row[1];
      $description = $row[2];
      $picture = $row[3];
      $zipname = $row[4];

      // FORMAT RESULTS
      echo $title." - ".$author."<br>\n";
      echo $description."  ".$picture."<br>\n";
      if(!empty($zipname))
         echo "<a href=\"".$zipname."\">$zipname</a><br>\n";
      echo "<br><br>\n";
   }
?>
quelle
New php-forum User
New php-forum User
 
Posts: 8
Joined: Tue Aug 20, 2002 11:57 am

Thx

Postby nindoja » Wed Mar 26, 2003 4:58 pm

Thx.
nindoja
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Jan 08, 2003 4:45 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron