wesleypipes Posted November 5, 2006 Share Posted November 5, 2006 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 https://forums.phpfreaks.com/topic/26240-can-some1-start-me-of-in-displaying-records-from-a-database/ Share on other sites More sharing options...
farris Posted November 5, 2006 Share Posted November 5, 2006 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 countryonce you has a query string that returns that 2 values you want, put that into a value in your phpif 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 resultslike 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 startany questions just ask Link to comment https://forums.phpfreaks.com/topic/26240-can-some1-start-me-of-in-displaying-records-from-a-database/#findComment-120044 Share on other sites More sharing options...
realjumper Posted November 5, 2006 Share Posted November 5, 2006 [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 getwhile($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 https://forums.phpfreaks.com/topic/26240-can-some1-start-me-of-in-displaying-records-from-a-database/#findComment-120054 Share on other sites More sharing options...
wesleypipes Posted November 5, 2006 Author Share Posted November 5, 2006 thankyou for your time realjumper and farris. Link to comment https://forums.phpfreaks.com/topic/26240-can-some1-start-me-of-in-displaying-records-from-a-database/#findComment-120058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.