ryanpratt Posted April 14, 2009 Share Posted April 14, 2009 Hello guys and girls, im having issues running a conditional inside a loop. The virst include is working but the include wont loop even thought the values are? Hope this make sense to you guys. Snippet area. <?php do { ?> <?php // Show IF Conditional region1 if (@$row_Recordset1['tittleX_name'] != @$row_Recordset2['tittleX_name']) { ?> <?php echo $row_Recordset1['tittleX_name']; ?><br /> <?php } // endif Conditional region1 ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> Page code <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $KTColParam1_Recordset1 = "0"; if (isset($_GET["temp_id"])) { $KTColParam1_Recordset1 = $_GET["temp_id"]; } mysql_select_db($database_CORE, $CORE); $query_Recordset1 = sprintf("SELECT tittleX.tittlex_weight, tittleX.tittleX_id, tittleX.tittleX_temp_id, tittleX.tittleX_hint, tittleX.tittleX_name FROM tittleX WHERE tittleX.tittleX_temp_id=%s ORDER BY tittleX.tittlex_weight ASC ", GetSQLValueString($KTColParam1_Recordset1, "int")); $Recordset1 = mysql_query($query_Recordset1, $CORE) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $KTColParam1_Recordset2 = "0"; if (isset($_GET["boat_id"])) { $KTColParam1_Recordset2 = $_GET["boat_id"]; } mysql_select_db($database_CORE, $CORE); $query_Recordset2 = sprintf("SELECT tittleX.tittleX_temp_id, tittleX.tittleX_name, fieldX.fieldX_address_id, fieldX.fieldX_id, tittleX.tittleX_id, fieldX.fieldX_tittle_id, tittleX.tittlex_weight, tittleX.tittleX_hint, fieldX.fieldX_value FROM (tittleX LEFT JOIN fieldX ON fieldX.fieldX_tittle_id=tittleX.tittleX_id) WHERE fieldX.fieldX_address_id=%s ORDER BY tittleX.tittlex_weight ASC ", GetSQLValueString($KTColParam1_Recordset2, "int")); $Recordset2 = mysql_query($query_Recordset2, $CORE) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="100%" border="0" cellpadding="20"> <tr> <td valign="top"> <?php do { ?> <?php // Show IF Conditional region1 if (@$row_Recordset1['tittleX_name'] != @$row_Recordset2['tittleX_name']) { ?> <?php echo $row_Recordset1['tittleX_name']; ?><br /> <?php } // endif Conditional region1 ?> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </td> <td valign="top"><?php do { ?> <?php echo $row_Recordset2['tittleX_name']; ?><br /> <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?></td> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); mysql_free_result($Recordset2); ?> This is probable something simple but i cant seam to figure it out. Please help. I will buy anyone who can fix this a pint. Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/ Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 What do you mean "include"? Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809775 Share on other sites More sharing options...
JonnoTheDev Posted April 14, 2009 Share Posted April 14, 2009 Doesn't! Which loop, you have a few. Can't see an include within a loop. Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809781 Share on other sites More sharing options...
ryanpratt Posted April 14, 2009 Author Share Posted April 14, 2009 not include wrong term. what im trying to do is display two lists on the page and have the first list not show the values which are contained in list 2. Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809783 Share on other sites More sharing options...
ryanpratt Posted April 14, 2009 Author Share Posted April 14, 2009 I supose my issue is that the {Recordset2.tittleX_name} does not change so i need to figure out how to make it change inside of the repeat region. what is the best way to do this? Ok, 2 Pints! Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809803 Share on other sites More sharing options...
JonnoTheDev Posted April 14, 2009 Share Posted April 14, 2009 You could store the results of 1 query into an array and then use the in_array function. Heres an example. $query1 = mysql_query("SELECT * FROM table1 WHERE field1='xyz'"); $temp = array(); while($row = mysql_fetch_assoc($query1)) { $temp[] = $row['title']; } $query2 = mysql_query("SELECT * FROM table2 WHERE field1='abc'"); while($row = mysql_fetch_assoc($query2)) { if(!in_array($row['title'], $temp)) { print $row['title']."<br />\n"; } } Ideally I would only use 1 query and rewrite it so I only return the results I require. However in your case I do not know your database design so this is a dirty method. Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809853 Share on other sites More sharing options...
ryanpratt Posted April 14, 2009 Author Share Posted April 14, 2009 Thanks, Neil. My db will not allow me to create this as one query as the items dont exist in the first query results, they are related to virtual tables which only exist in the second query. This probably makes little or no sense to you since im not good at explain my logic. Would you be willing to show me how to do this for a fee? Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809873 Share on other sites More sharing options...
JonnoTheDev Posted April 14, 2009 Share Posted April 14, 2009 Then use the method I have shown you above. This is easy enough. Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809880 Share on other sites More sharing options...
Nazirul Posted April 14, 2009 Share Posted April 14, 2009 $query2 = mysql_query("SELECT * FROM table2 WHERE field1='abc'"); while($row = mysql_fetch_assoc($query2)) { if(!in_array($row['title'], $temp)) { print $row['title']."<br />\n"; } } Neil, regarding your code... how about if we want to search only from 1 table with conditional statement... i just want to use if(!in_array($row['title'], $temp)) { print $row['title']."<br />\n"; } else { echo ("no data on your query"); } is it possible? .. Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809897 Share on other sites More sharing options...
JonnoTheDev Posted April 14, 2009 Share Posted April 14, 2009 No, your issue is different. Im guessing your just after if the query returns 0 rows. Here's how: if(!mysql_num_rows($query)) { echo ("no data on your query"); } else { while($row = mysql_fetch_assoc($query)) { } } Quote Link to comment https://forums.phpfreaks.com/topic/154049-solved-issue-with-php-conditional-statment/#findComment-809903 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.