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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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