hyster Posted November 21, 2010 Share Posted November 21, 2010 im stuck on this section of code atm its failing on the line "or die(mysql_error());" i think its the $table ifs. ive tryed "" around the query but i get other errors then <?php if ($_GET['make'] == ''){ //no input //all if ($_GET['make'] == 'all'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments like '{$_GET['make']}'"); //pass if ($_GET['make'] == 'pass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments like '{$_GET['make']}'"); //not pass if ($_GET['make'] == 'notpass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments not like '{$_GET['make']}'"); }else{ //by make $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments not like '{$_GET['make']}'"); } } } } ?> <div id="right"> <?php echo "$table"; or die(mysql_error()); $result=mysql_query($sql); ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 21, 2010 Share Posted November 21, 2010 You can't open a statement with 'or'. Perhaps this is what you meant to do? echo "$table"; $result=mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted November 21, 2010 Share Posted November 21, 2010 Use the switch statement. Quote Link to comment Share on other sites More sharing options...
hyster Posted November 21, 2010 Author Share Posted November 21, 2010 the problem was echo "$table"; // ; stopped the code when it shoudnt have stopped and i was echoing the $ $result=mysql_query($sql) or die(mysql_error()); i decided to do this another way and thought i had problem in the code but the code works as writen. the problem i face now is that the if's stop before the else statment where as i want the <table> to be used by the if's and the else. i wanted to get away from duplicateing the code so i used ifs and i cannot think of another way of doing it. <?php if ($_GET['make'] == ''){ //no input } //all elseif ($_GET['make'] == 'all'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval"); } //pass elseif ($_GET['make'] == 'pass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments like 'Pass'"); } //not pass elseif ($_GET['make'] == 'notpass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments not like 'pass'"); }else{ //by make $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where make like '{$_GET['make']}'"); ?> <div id="right"> <?php $table or die(mysql_error()); $result=mysql_query($sql); ?> <table> some code </table> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 21, 2010 Share Posted November 21, 2010 This makes no sense at all: $table or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
hyster Posted November 21, 2010 Author Share Posted November 21, 2010 $table = the sql query from the if's i solved it by another set of if's derived from the 1st set. if possable could i get a critique of my finished code pls? id like to no what i could have done diffrently or better. big thanks. working page http://sts.hostei.com/dsgi/test.php <style> #left { width: 300px; border: 1px solid red; float: left } #right { width: 300px; border: 1px solid red; float: right } <div id="main"> <div id="left"> </style> <?php include("config.php"); // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "SELECT make, COUNT(*) AS total, SUM(IF(comments = 'pass', 1, 0)) AS withComments, SUM(IF(comments not like 'pass', 1, 0)) AS withnotval FROM dsgi_serval GROUP BY make ORDER BY COUNT(*) DESC"; $result=mysql_query($sql); ?> <tr> <td><table width="319" border="1" align="center" id="left"> <tr> <td colspan="4"><div align="center"><font size="4" face="Verdana"><strong>Validation Total's </strong></font></div></td> </tr> <tr> <td width="137" align="center"><strong>Make</strong></td> <td width="85" align="center"><strong>Total</strong></td> <td width="75" align="center"><strong>Validated</strong></td> <td width="75" align="center"><strong>Not Validated</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><div align="center"><a href="?make=<?php echo $rows['make']; ?>"><?php echo $rows['make']; ?></a></div></td> <td><div align="center"><?php echo $rows['total']; ?></div></td> <td><div align="center"><?php echo $rows['withComments']; ?></div></td> <td><div align="center"><?php echo $rows['withnotval']; ?></div></td> </tr> <?php } ?> <tr> <td><div align="center">Totals</div></td> <td><div align="center"> <?php // counts all rows $query = "SELECT make, COUNT(make) FROM dsgi_serval "; $result1 = mysql_query($query) or die(mysql_error()); while($row1 = mysql_fetch_array($result1)){ ?> <a href="?make=all"><?php echo $row1['COUNT(make)']?></a> <?php } ?> </div></td> <td><div align="center"> <?php // counts validated $query = "SELECT make, COUNT(make) FROM dsgi_serval where comments like 'pass'"; $result2 = mysql_query($query) or die(mysql_error()); while($row2 = mysql_fetch_array($result2)){ ?> <a href="?make=pass"><?php echo $row2['COUNT(make)']?></a> <?php } ?> </div></td> <td><div align="center"> <?php // counts not validate $query = "SELECT make, COUNT(make) FROM dsgi_serval where comments not like 'pass'"; $result3 = mysql_query($query) or die(mysql_error()); while($row3 = mysql_fetch_array($result3)){ ?> <a href="?make=notpass"><?php echo $row3['COUNT(make)']?></a> <?php } ?> </div></td> </tr> </table> </div></td> </tr> </table> <?php if ($_GET['make'] == ''){ //no input } //all elseif ($_GET['make'] == 'all'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval"); } //pass elseif ($_GET['make'] == 'pass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments like 'Pass'"); } //not pass elseif ($_GET['make'] == 'notpass'){ $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where comments not like 'pass'"); }else{ //by make $table = $result6 = mysql_query("SELECT * FROM dsgi_serval where make like '{$_GET['make']}'"); } if ($table == ''){ }else{ ?> <div id="right"> <?php $table or die(mysql_error()); $result=mysql_query($sql); ?> </p> <table id="right" width="888" border="1" align="center"> <tr> <td colspan="10"><div align="center"><font size="4" face="Verdana"><strong>Validation Total's </strong></font></div></td> </tr> <tr> <td width="46" align="center"><strong> Sku</strong></td> <td width="95" align="center"><strong> Orig Sku</strong></td> <td width="67" align="center"><strong> Make</strong></td> <td width="72" align="center"><strong> Model</strong></td> <td width="111" align="center"><strong> Comments</strong></td> <td width="67" align="center"><strong> Sound</strong></td> <td width="95" align="center"><strong> Graphics</strong></td> <td width="102" align="center"><strong> Recovery</strong></td> <td width="56" align="center"><strong> Date</strong></td> <td width="113" align="center"><strong> Validate By</strong></td> </tr> <?php ?> <?php while($rows=mysql_fetch_array($result6)){ $case = strtoupper($rows['comments']); if ($case == 'PASS') { $bgc="#33ff00"; } else { $bgc="#ff0000"; } ?> <tr bgcolor=<?php echo $bgc;?>> <td><div align="center"> <?php echo $rows['sku']; ?></div></td> <td><div align="center"> <?php echo $rows['rsku']; ?></div></td> <td><div align="center"> <?php echo $rows['make']; ?></div></td> <td><div align="center"> <?php echo $rows['model']; ?></div></td> <td><div align="center"> <?php echo $rows['comments']; ?></div></td> <td><div align="center"> <?php echo $rows['sound']; ?></div></td> <td><div align="center"> <?php echo $rows['gfx']; ?></div></td> <td><div align="center"> <?php echo $rows['recovery']; ?></div></td> <td><div align="center"> <?php echo $rows['date']; ?></div></td> <td><div align="center"> <?php echo $rows['valby']; ?></div></td> </tr> <?php } } ?> </table> <?php mysql_close(); ?> </div> </div> Quote Link to comment 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.