Results 1 to 2 of 2
  1. #1

    Accessing SQL data on webpage


    Im new here, and hopefully after a bit of help!!

    I have got a website which access a lot of data off the SQL server and shows it on a web page.
    What i am finding is that it is taking a while to load and was just wondering if the coding is wrong or if there is anything i can do to improve it?

    Coding to produce results in HTML page shown below:

    //connect to server with username and password
    $connection = mysql_connect ("localhost","<USERNAME>", "<PASSWORD>") or die ("Cannot make the connection");
    //connect to database
    $db = mysql_select_db ("<DATABASE>",$connection) or die ("Cannot connect to database");
    //our SQL query

    $sql_query = "SELECT * FROM hiredeals ORDER BY id ASC";
    //store the SQL query in the result variable
    $result = mysql_query($sql_query);
    //output as long as there are still available fields
    while($row = mysql_fetch_row($result))
    echo ("<tr class=\"box$row[8]\"><td><a href=\"javascript:CarEnquiry('cardetail.php?car_id=$row[0]')\" class=\"box$row[8]\"><strong>$row[2]</strong></td><td><center>$row[3]</center></td><td>$row[4]</td><td><a href=\"javascript:CarEnquiry('cardetail.php?car_id=$row[0]')\" class=\"box$row[8]\">$row[5]</a></td><td><center>$row[6]</center></td><td><center>$row[7]</center></td><td><center>$row[10]</center></td><td><center>$row[11]</center></td></tr><tr><td height=\"1\" colspan=\"8\" background=\"img/line_bkg.gif\"><img src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td></tr>");

    //if no fields exist
    echo "no values in the database";


    Can someone let me know if there is anything wrong with the coding or if there is something we can do to improve speed, the above code grabs about 280 rows and chucks the data into the web page.

    Many thanks in advance!!


  2. #2
    Join Date
    Apr 2005
    The code to me seems ok, but displaying allot of data on a web page is normally not a good idea.

    The best thing to do is use pagination, display 30 rows at a time and let the user cycle though them.

    There should be loads of source code out there to do pagination, but here is a sample class.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts