Jump to content

[SOLVED] Syntax Error in PHP SQL Query


dgmuk

Recommended Posts

Hi,

 

I am trying to get results from a sql query to display in a table, formatted to two columns (i.e.:

 

Result1 Result2

Result3 Result4

Result5 Result6

 

etc!

 

However I am getting this error and I can't work out why:

 

Parse error: syntax error, unexpected ';', expecting ')' in /home/sites/regencynet.com/public_html/phonesearch2.php on line 15

 

This is the script I am using:

 

<?php

//set the number of columns

$columns = 2;

 

mysql_connect('localhost',products-24','4758112542');

mysql_select_db(products-24');

$query = "SELECT * FROM infoproducts ORDER BY IDC";

$result = mysql_query($query);

 

//we add this line because we need to know the number of rows

$num_rows = mysql_num_rows($result);

echo "<TABLE BORDER=\"0\">\n";

 

//changed this to a for loop so we can use the number of rows

for($i = 0; $i < $num_rows; $i++) {

    $row = mysql_fetch_array($result);

    if($i % $columns == 0) {

        //if there is no remainder, we want to start a new row

        echo "<TR>\n";

    }

    echo "<TD>" . $row['IDC'] . "</TD>\n";

    if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {

        //if there is a remainder of 1, end the row

        //or if there is nothing left in our result set, end the row

        echo "</TR>\n";

    }

}

echo "</TABLE>\n";

?>

 

Can anyone help please?

Link to comment
https://forums.phpfreaks.com/topic/58202-solved-syntax-error-in-php-sql-query/
Share on other sites

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.