Jump to content

Can some1 start me of in displaying records from a database?


wesleypipes

Recommended Posts

My 'sports' page has three pictures(not loaded from a database but just created myself). U click on these links and it shows you(on a seperate page and displayed in a table) the records from a specific table from the database. Lets just say to display fields 'league', 'country'. I know ill have to start the php script with connecting to a database and a specific table, but how do i go about displaying the records from table. Also, the records must be stored in table.

Please help a beginner  8)  ;D
im fairly new at this too but this is how ive been doing it...
after you select the table you have to query the database using "mysql_query()"
what you can do is access your mysql database and use a regular query string till you get the query string that you need such as
[code]"SELECT league , country FROM tablename WHERE picture = "(some kind of identifer here)"[/code]
that assumes the table your searching is called "tablename". it returns the fields league and country

once you has a query string that returns that 2 values you want, put that into a value in your php
if the query above worked then it would look like this
[code]$findLeagueCountry = "SELECT league , country FROM tablename WHERE picture = "$picture";[/code]
you should make some kind of variable, such as "$picture", that holds a value that corresponds with the  picture

then put that query string into the "mysql_query()" and report that data into a $result variable like this
[code]$result = mysql_query($findLeagueCountry);[/code]

then you have to pull the information out of the $result something like this
[code]while($row = mysql_fetch_array($result))
  {
  echo ($row['league']) ;
  echo ("<br>") ;
  echo ($row['country']) ;
  }[/code]
that *should* loop through the results and print out the results
like i said im kinda new at this too but this is how ive been doing it with some login scripts ive been working on but it should give you a start
any questions just ask
[code]

// Get all the data from the "your_table" table


$result = mysql_query("SELECT league,country FROM your_table")
or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>League</th> <th>Country</th> </tr>";


// keeps getting the next row until there are no more to get


while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['league'];
echo "</td><td>";
echo $row['country'];
echo "</td></tr>";
}

echo "</table>";

[/code]

Archived

This topic is now archived and is closed to further replies.

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