Jump to content

Efficient PHP MySQL


thunderousity

Recommended Posts

I usually use the following syntax for my php pages

 

mysql_select_db($database_school, $school);$query_Recordset1 = "SELECT * FROM tblSchool";$Recordset1 = mysql_query($query_Recordset1, $school) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 

and use something like this to echo the results

 

echo "<table border='1'>< tr>< th>Firstname</th>< th>Lastname</th>< /tr>";while($row = mysql_fetch_assoc($Recordset1)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; }echo "</table>";

 

Scenario:

 

I usually do 2 separate PHP/MYSQL statements as above with 2 separate results but that doesn't seem very efficient.

 

In a bid to be more efficient what if I have 1 query which returns 2 rows but I want to echo the first row of results on one side of the web page and the second somewhere completely different on the page. I can't really use a 'while' statement as it's not really a list.

 

I'm guessing I'd have to put it in an array where I can specify which row I want to echo?

Edited by thunderousity
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...