wooowooo Posted December 27, 2007 Share Posted December 27, 2007 hi all, dont know why this isnt working Atm got an error on line 17 T_string expeting ( <?php // connect to db $num_fields= mysql_num_fields($query_result ); if ($num_fields) { //build the order by row echo "<tr>" ; for ($i = 0; $i < $num_fields; $i++) { $colname = mysql_field_name($query_result , $i) ; //build a default header for both ascending and descending link $orderlink = ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . "&sort=desc\" title=\"Sort the records in descending order\">Sort descending</a>") ; $orderlink .= " " ; $orderlink .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . "&sort=asc\" title=\"Sort the records in ascending order\">Sort ascending</a>") ; if $_GET['columnname']== $colname { if ($order=="asc") { $orderlink = ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname ." &sort=desc\" title=\"Sort the records in descending order\">Sort descending</a>") ; // default replaced by single link } else { $orderlink = ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . "&sort=asc\" title=\"Sort the records in ascending order\">Sort ascending</a>") ; } } echo ("<td>" . $orderlink . "</td>" ; // place each link-couplein a new cell } echo "</tr>" ; } else { echo "Empty recordset" ; } //and then here comes your code to display the records from the recordset. while ($row = @mysql_fetch_array ($query_result)) { echo " <tr align=\"center\" bgcolor=\"$row[colourcode]\"> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[CustomerID]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Name]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Address]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Postcode]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Telephone]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Email]</font></td> </tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/ Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Indent your code, it will be easier to find the missing bracket. Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423808 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Where do you set $order? Looks like you are missing $order = $_GET['order']; before if ($order=="asc") Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423809 Share on other sites More sharing options...
wooowooo Posted December 27, 2007 Author Share Posted December 27, 2007 if ($order=="asc") { Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423814 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Yeah, but if $order won't do no good if you don't have anything in the $order variable right? Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423815 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Also change if $_GET['columnname']== $colname { to if ($_GET['columnname']== $colname) { Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423817 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 And remove the ( from here echo ("<td>" . $orderlink . "</td>" ; // place each link-couplein a new cell echo "<td>" . $orderlink . "</td>" ; // place each link-couplein a new cell Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423818 Share on other sites More sharing options...
marcus Posted December 27, 2007 Share Posted December 27, 2007 <?php // connect to db $num_fields = mysql_num_fields($query_result); if ($num_fields) { //build the order by row echo "<tr>"; for ($i = 0; $i < $num_fields; $i++) { $colname = mysql_field_name($query_result, $i); //build a default header for both ascending and descending link $orderlink = ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . "&sort=desc\" title=\"Sort the records in descending order\">Sort descending</a>"); $orderlink .= " "; $orderlink .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . "&sort=asc\" title=\"Sort the records in ascending order\">Sort ascending</a>"); if ($_GET['columnname'] == $colname) { if ($order == "asc") { $orderlink = ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . " &sort=desc\" title=\"Sort the records in descending order\">Sort descending</a>"); // default replaced by single link } else { $orderlink = ("<a href=\"" . $_SERVER["PHP_SELF"] . "?columnname=" . $colname . "&sort=asc\" title=\"Sort the records in ascending order\">Sort ascending</a>"); } } echo "<td>" . $orderlink . "</td>"; // place each link-couplein a new cell } echo "</tr>"; } else { echo "Empty recordset"; } //and then here comes your code to display the records from the recordset. while ($row = @mysql_fetch_array($query_result)) { echo "<tr align=\"center\" bgcolor=\"$row[colourcode]\"> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[CustomerID]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Name]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Address]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Postcode]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Telephone]</font></td> <td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#006699\"> $row[Email]</font></td> </tr>"; } ?> neat too. Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423823 Share on other sites More sharing options...
wooowooo Posted December 27, 2007 Author Share Posted December 27, 2007 Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in /home/.julia/bex/bex.st18.co.uk/wk8ex3.2.php on line 10 Empty recordset Still not working Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423830 Share on other sites More sharing options...
marcus Posted December 27, 2007 Share Posted December 27, 2007 Your fault not ours. $whateveryourqueryvariableiscalled = mysql_query("w/e") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423833 Share on other sites More sharing options...
trq Posted December 27, 2007 Share Posted December 27, 2007 You are the one responisble for debuging your own code. That error usually means your query is failing and you have failed to check it for success prior to trying to use its result. Fix it. Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423835 Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 You don't even have $query_result defined in your code. Quote Link to comment https://forums.phpfreaks.com/topic/83296-anyone-debug-this/#findComment-423837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.