PHP - Moved: Problem In Condition And Logic To Get The Last Row Data And Displayed
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=359434.0 Similar TutorialsHello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355229.0 Hi.. I have query for insert then I just want to add condition that after it save it will locate on the previous page: here is my code: Code: [Select] $sql = "INSERT INTO receiving_materials (sr_date, sr_number, si_num, s_name, po_num, qty, mat_code, mat_desc, wh_code, bin_loc) VALUES ('$sr_date', '$sr_number', '$si_num', '$s_name', '$po_num', '$qty', '$mat_code', '$mat_desc', '$wh_code', '$bin_loc') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', si_num = '$si_num', s_name = '$s_name', po_num = '$po_num', qty = '$qty', mat_code = '$mat_code', mat_desc = '$mat_desc', wh_code = 'wh_code', bin_loc = '$bin_loc'"; $res_receiving = mysql_query($sql, $con) or die(mysql_error()); Thank you This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321443.0 I'm teaching myself how to use php and mysql... I created a form to insert data into a mysql database, all went well and when I returned to the form it was blank. I then asked a friend to test it out aswell and when he loaded the form page, the data that entered before him was displayed? (it was still filled out with my info). Even after he refreshed it was still there... Hows this possible? How would I clear the form after its been submitted if it doesnt do it automatically? Thanks Drew Hello, I have a stock page on my site and want to use the code to display a small stock area on my home page. I am not sure on how I would limit the number of records or randomize the records shown. The code is Code: [Select] <?php $coachselect=mysql_query("SELECT * FROM coaches WHERE DISPLAY = '1' ORDER BY STOCK")or die(mysql_error()); while($row = mysql_fetch_array($coachselect)){ ?> <ul class="stock-home"> <li><h4><a href="details-id-<?php echo $row['ID']; ?>.html" target="_blank"></a></h4></li> <li><img src="./<?php echo $row['IMAGES'] . "/" . $row['DEFAULT_IMAGE'] ; ?>" width="187" height="138" alt="lehel virage for sale" class="fl"/></li> <li><?php echo $row['NAME']; ?></h3></li><li><?php echo $row['DESC_SHORT']; ?></li> <li><a href="details.php?id=<?php echo $row['ID']; ?>" target="_blank">more info...</a></li> <li><?php echo $row['DESC_2']; ?></li> </ul><!--close stock home--> <?php } ?> I am guessing that something needs to be added here Code: [Select] $coachselect=mysql_query("SELECT * FROM coaches WHERE DISPLAY = '1' ORDER BY STOCK")or die(mysql_error()); while($row = mysql_fetch_array($coachselect)){ ?> But am not sure how to do it? Does anyone have any advice or could point me to a tutorial? Here is the rest of the code, from the top of the page. Code: [Select] $CON=mysql_connect($DB_SERVER, $DB_USER, $DB_PASS) or die(mysql_error()); $DB_SELECT=mysql_select_db($DATABASE) or die(mysql_error()); if (isset($_POST)) { foreach ($_POST as &$value) { $value = trim(htmlspecialchars($value, ENT_QUOTES)); } } if (isset($_GET)) { foreach ($_GET as &$value) { $value = trim(htmlspecialchars($value, ENT_QUOTES)); } } $_SERVER['PHP_SELF'] = filter_var($_SERVER['PHP_SELF'], FILTER_SANITIZE_STRING); ?> Many Thanks Dan I am trying to write some code to display the visits to my site each week in batches of 13 weeks (1 quarter).
I am getting the Week No and the number of hits, but the actual date, which is in a separate table is not being displayed.
I have tried LEFT JOIN and INNER Join and even RIGHT JOIN (this only displays the Date).
I can't see where I am going wrong!
Here is the code:
<? include('connect_visits.php'); doDB7(); $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT Visits.ID, Visits.WVisits, Visits.WCom, WeekNo.WNo, WeekNo.WCom FROM Visits LEFT JOIN WeekNo ON Visits.ID = WeekNo.WCom ORDER BY Visits.ID LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['ID']; $Visits = ($C_info['WVisits']); $WeekNo = ($C_info['WCom']); //add to display $display_block .= " <tr> <td width=\"1%\" valign=\"top\">".$Cid."<br/></td> <td width=\"8%\" valign=\"top\">".$WeekNo."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> </td></tr>"; } mysqli_free_result($Visit_data_res); ?>Where am I going wrong? Edited by rocky48, 29 December 2014 - 12:53 PM. This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=309496.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=325313.0 Hi.. I tried this code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); mysql_select_db("mes", $con); if (!$con) { echo 'failed'; die(); } $sql = "SELECT PCODE, total FROM kanban_checker ORDER BY PCODE"; $res = mysql_query($sql, $con) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $PCODE = $row['PCODE']; $total = $row['total']; } $sql = "SELECT P28, P28_max, P28_min, P30, P30_max, P30_min, P32, P32_max, P32_min, P33, P33_max, P33_min, P35, P35_max, P35_min, P35M, P35M_max, P35M_min, P35W, P35W_max, P35W_min, P38, P38_max, P38_min, P41, P41_max, P41_min, P42, P42_max, P42_min, P43, P43_max, P43_min, P46, P46_max, P46_min FROM parameter_settings"; $res_pcode = mysql_query($sql, $con); $row = mysql_fetch_assoc($res_pcode); $P28 = $row['P28']; $P28_max = $row['P28_max']; $P28_min = $row['P28_min']; $P30 = $row['P30']; $P30_max = $row['P30_max']; $P30_min = $row['P30_min']; $P32 = $row['P32']; $P32_max = $row['P32_max']; $P32_min = $row['P32_min']; $P33 = $row['P33']; $P33_max = $row['P33_max']; $P33_min = $row['P33_min']; $P35 = $row['P35']; $P35_max = $row['P35_max']; $P35_min = $row['P35_min']; $P35M = $row['P35M']; $P35M_max = $row['P35M_max']; $P35M_min = $row['P35M_min']; $P35W = $row['P35W']; $P35W_max = $row['P35W_max']; $P35W_min = $row['P35W_min']; $P38 = $row['P38']; $P38_max = $row['P38_max']; $P38_min = $row['P38_min']; $P41 = $row['P41']; $P41_max = $row['P41_max']; $P41_min = $row['P41_min']; $P42 = $row['P42']; $P42_max = $row['P42_max']; $P42_min = $row['P42_min']; $P43 = $row['P43']; $P43_max = $row['P43_max']; $P43_min = $row['P43_min']; $P46 = $row['P46']; $P46_max = $row['P46_max']; $P46_min = $row['P46_min']; $P47 = $row['P47']; $P47_max = $row['P47_max']; $P47_min = $row['P47_min']; if($PCODE = $P28 || $total = $P28_min){ echo $P28_min; } elseif($PCODE = $P30 || $total = $P30_min){ echo $P30_min; } elseif($PCODE = $P32 || $total = $P32_min){ echo $P32_min; } elseif($PCODE = $P33 || $total = $P33_min){ echo $P33_min; } elseif($PCODE = $P35 || $total = $P35_min){ echo $P35_min; } elseif($PCODE = $P35M || $total = $P35M_min){ echo $P35M_min; } elseif($PCODE = $P35W || $total = $P35W_min){ echo $P35W_min; } elseif($PCODE = $P38 || $total = $P38_min){ echo $P38_min; } elseif($PCODE = $P41 || $total = $P41_min){ echo $P41_min; } elseif($PCODE = $P42 || $total = $P42_min){ echo $P42_min; } elseif($PCODE = $P43 || $total = $P43_min){ echo $P43_min; } elseif($PCODE = $P46 || $total = $P46_min){ echo $P46_min; } elseif($PCODE = $P47 || $total = $P47_min){ echo $P47_min; } else{ echo ''; } ?> for display data if total = min. The problem is, in this condition he satisfied if condition even though $total is not equal to $P28_min. Thank you Hi.. I got problem in logic on my problem in select option. Here is my scenario. I have select option which has a compound list: example: P28 P30 P32 P33 P35 and I have tables which has a total count of compound that was already transact. for example I already transact 10 P28 compound. it will save in kanban_checker table field Total. and I have parameter_settings table which has the maximum and minimum per compound: fields----------data P28------------P28 P28_max-----10 P28_min------6 P30------------P28 P30_max-----10 P30_min------6 P32------------P28 P32_max-----10 P32_min------6 P33------------P28 P33_max-----10 P33_min------6 now the logic is: if P28 total = P28_max then notify that he already reach the maximum..it will not produce P28 because he already reach the maximum. if P28 total = P28_min then produce P28. same with other compound. Now, I got a problem in coding and logic, because in the select option I'm not the one who code it.. I just one who need to add the additional function.. here is the code for select option and the function that was created by other, Code: [Select] $smarty->assign('text_name1','Compound Code'); $smarty->assign('compoundIndexValue', array('0', 'P28', 'P30', 'P32', 'P33', 'P35', 'P35M', 'P38', 'P40', 'P41', 'P42', 'P43', 'P46', 'P47', 'PXX', 'P35W')); <tr> <td class="tdMainText">{$text_name1}</td> <td> <select class="tdMainElement" id="selCompound" onchange="isSelected('selCompound','txtLotCode')" onclick="clearNotify()" onblur="this.focus();" onkeypress="return false">{html_options values=$compoundIndexValue output=$names selected="0"} </select> </td> </tr> <script type="text/javascript"> function isSelected(obj1, obj2) { if (!document.getElementById(obj1).disabled) { document.getElementById(obj1).disabled = true; } if (document.getElementById('clear').disabled) { document.getElementById('clear').disabled = false; //enable it } if ((document.getElementById('chkDownGrade') != null)) { if (!document.getElementById('chkDownGrade').disabled) { document.getElementById('chkDownGrade').disabled = true; } } if (document.getElementById(obj2).disabled) { document.getElementById(obj2).disabled = false; } document.getElementById(obj2).focus(); document.getElementById(obj2).focus(); //notify("Gain Maximum Total"); } function disable() { if (!document.getElementById('clear').disabled) { document.getElementById('clear').disabled = true; } else { document.getElementById('clear').disabled = false; } } function clearNotify() { if (document.getElementById('notice') != null) { document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box } } </script> and here is the code that I tried to add: Code: [Select] $compound = mysql_real_escape_string($_POST['compound']); $sql = "SELECT P28, P28_max, P28_min, P30, P30_max, P30_min, P32, P32_max, P32_min, P33, P33_max, P33_min, P35, P35_max, P35_min, P35M, P35M_max, P35M_min, P35W, P35W_max, P35W_min, P38, P38_max, P38_min, P41, P41_max, P41_min, P42, P42_max, P42_min, P43, P43_max, P43_min, P46, P46_max, P46_min FROM parameter_settings"; $res_pcode = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_pcode)){ $P28 = $row['P28']; $P28_max = $row['P28_max']; $P28_min = $row['P28_min']; $P30 = $row['P30']; $P30_max = $row['P30_max']; $P30_min = $row['P30_min']; $P32 = $row['P32']; $P32_max = $row['P32_max']; $P32_min = $row['P32_min']; $P33 = $row['P33']; $P33_max = $row['P33_max']; $P33_min = $row['P33_min']; $P35 = $row['P35']; $P35_max = $row['P35_max']; $P35_min = $row['P35_min']; $P35M = $row['P35M']; $P35M_max = $row['P35M_max']; $P35M_min = $row['P35M_min']; $P35W = $row['P35W']; $P35W_max = $row['P35W_max']; $P35W_min = $row['P35W_min']; $P38 = $row['P38']; $P38_max = $row['P38_max']; $P38_min = $row['P38_min']; $P41 = $row['P41']; $P41_max = $row['P41_max']; $P41_min = $row['P41_min']; $P42 = $row['P42']; $P42_max = $row['P42_max']; $P42_min = $row['P42_min']; $P43 = $row['P43']; $P43_max = $row['P43_max']; $P43_min = $row['P43_min']; $P46 = $row['P46']; $P46_max = $row['P46_max']; $P46_min = $row['P46_min']; $P47 = $row['P47']; $P47_max = $row['P47_max']; $P47_min = $row['P47_min']; } // $sub_lotcode = substr($lotCode, 9, 4); $sql = "SELECT PCODE, total FROM kanba_checker WHERE PCODE = '$sub_lotcode' ORDER BY PCODE"; $res_kanban = mysql_query($sql, $con); $row_kanban = mysql_fetch_assoc($res_kanban); $PCODE = $row_kanban['PCODE']; $total = $row_kanban['total']; if($compound = $P28 || $total == $P28_max){ echo "<script type='text/javascript'>alert(P28 gain total maximum)</script>"; } else{ } but I don't know if my code and my logic is correct. I think I did to add function. But I don't know how.. I hope someone can help me or guide me to solve my problem. Thank you so much.. hi guys usename:password user1:pass1 user2:pass2 user3:pass2 i have a function fun(username,pass) and i want to run it for lots of different user names and passwords. what would the best way to do this? would i make an array and use a foreach loop or how would i do it and what could would i need?? So the code works right, (I think) but for some reason the way I built it the logic comes back null. I can do All w a specific shift/s, and All with department/s but I can't do All shifts and All departments it doesn't' error either, just brings back nothing, maybe timing out? I'm very new at this so I apologize in advance. Code below ############################################################ <form method="post" action=""> <br><br> <table bordercolor="yellow" border="2"> <tr><td class="line"><b>Start Date:</b></td><td> <input type="text" name="startdate" value="mm/dd/yyyy" /></td></tr> </tr> <tr><td class="line"><b>End Date:</b></td><td> <input type="text" name="enddate" value="mm/dd/yyyy" /></td></tr> </tr> <tr><td class="line"><b>Shift:</b></td><td> <SELECT NAME="shift" > <option selected>Select Shift</option> <option>First</option> <option>Second</option> <option>Third</option> <option>All</option> </SELECT> </td></tr> <tr><td class="line"><b>Department:</b></td><td> <SELECT NAME="department" > <option selected>Select Department</option> <option>Advanced Hosting Support</option> <option>Server Support</option> <option>Managed Support</option> <option>All</option> </SELECT> </td></tr> </tr> </tr> </table> <br><br> <input type="submit" value="submit" /> </form> <form action="" method="post"> </form> </html> <?php require_once('global.inc.php'); class DataLogic { //function to obtain Employee names from RealID array to pass to MSSQL for call count function GetEmpNames ($RealID) { global $ems_db_connect; foreach ($RealID as $emplist){ $query1 = mysql_query ("SELECT FirstName, LastName FROM ems_employee_list WHERE RealID=$emplist", $ems_db_connect) or die(mysql_error());; while($row = mysql_fetch_array($query1)) { $FirstName[] = $row['FirstName']; $LastName[] = $row['LastName']; } } $friendlyname = array('first_name' => $FirstName, 'last_name' =>$LastName); return $friendlyname; } //function to display Employee names from RealID array obtained from department and shift function DisplayEmpNames ($RealID) { global $ems_db_connect; foreach ($RealID as $emplist){ $query1 = mysql_query ("SELECT FirstName, LastName FROM ems_employee_list WHERE RealID=$emplist", $ems_db_connect) or die(mysql_error());; while($row = mysql_fetch_array($query1)) { $FirstName = $row['FirstName']; $LastName = $row['LastName']; $fullname[] = "$LastName, $FirstName"; } } return $fullname; } //function to pull the RealID's of Employees based on shift //Returns a list of RealID's for use with GetIris and RepSort functions function SelectEmpShift ($key) { global $ems_db_connect; switch($key) { case "First": $shift = 1; break; case "Second": $shift = 2; break; case "Third": $shift = 3; break; default: $shift = 4; } if ($shift == 4){ $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND Department='AHS'", $ems_db_connect) or die(mysql_error()); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } else { $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND Shift = $shift AND Department ='AHS'", $ems_db_connect); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } return $x; } //Function to Select Employees based on Department function SelectEmpDep ($key) { global $ems_db_connect; switch($key) { case "Managed Support": $deptcode = 6; break; case "Server Support": $deptcode = 5; break; case "Advanced Hosting Support": $deptcode = 2; break; default: $deptcode = 7; } if ($deptcode == 7){ $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND Department='AHS'", $ems_db_connect) or die(mysql_error()); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } elseif ($deptcode == 5){ $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND AccessID=5 OR AccessID=3 AND Department='AHS' AND RealID >0", $ems_db_connect) or die(mysql_error()); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } else { $query1 = mysql_query ("SELECT RealID FROM ems_employee_list LEFT JOIN ems_employee_schedules USING (EmployeeID) WHERE RealID > 0 AND AccessID=$deptcode AND Department ='AHS' ", $ems_db_connect); while ($row = mysql_fetch_array($query1)) { $x[]=$row['RealID']; } } return $x; } //function to sort Shift by multiple Deparments function RepSortShiftDept ($RealIDShift, $RealIDDepartment='', $RealIDDepartment2='') { $deptnumber = func_num_args(); if ($deptnumber == 1) { $result = $RealIDShift; } elseif ($deptnumber == 2) { $result = array_intersect($RealIDShift, $RealIDDepartment); } else { $result = array_intersect($RealIDShift, array_merge($RealIDDepartment, $RealIDDepartment2)); } return $result; } //function to sort Department by multiple Shifts function RepSortDeptShift ($RealIDDepartment, $RealIDShift='', $RealIDShift2='') { $shiftnumber = func_num_args(); if ($shiftnumber == 1) { $result = $RealIDDepartment; } elseif ($shiftnumber == 2) { $result = array_intersect($RealIDDepartment, $RealIDShift); } else { $result = array_intersect($RealIDDepartment, array_merge($RealIDShift, $RealIDShift2)); } return $result; } //Function to get and display count of Iris tickets from a date rage. //$RealID needs to be an array of EmployeeIDs obtained from SelectEmpShift, SelectEmpDepart, and RepSort functions function GetIris($RealID, $startdate, $enddate) { global $hocstat_db_connect; foreach ($RealID as $emplist){ $mssqlquery = "SELECT COUNT (IncidentID) AS mycount FROM hocstats.dbo.DailyStatsEmployee WHERE hocstats.dbo.DailyStatsEmployee.EmployeeID=$emplist AND(hocstats.dbo.DailyStatsEmployee.DateModified BETWEEN '$startdate 00:00:00.000' AND '$enddate 23:59:59.000')"; $query_3 = mssql_query ($mssqlquery, $hocstat_db_connect); $row =(mssql_fetch_array($query_3)) ; $iriscount[] = $row['mycount']; } return $iriscount; } //Function to get and display call counts from a date range. For use with GetEmpName ONLY function GetCalls ($friendlyname, $startdate, $enddate) { global $hocstat_db_connect; for ($x = 0; $x < count ($friendlyname['last_name']); $x++) { $query1 ="SELECT ISNULL(SUM(CallsHandledToHalf), 0) AS calls FROM Agent_Skill_Group_Half_Hour ASGHH WITH (NOLOCK) INNER JOIN dbo.agent ON ASGHH.skilltargetid = dbo.agent.skilltargetid WHERE(dbo.agent.enterprisename = 'HOC_{$friendlyname['last_name'][$x]}_{$friendlyname['first_name'][$x]}' OR dbo.agent.enterprisename = '{$friendlyname['last_name'][$x]}_{$friendlyname['first_name'][$x]}') AND (ASGHH.datetime BETWEEN '$startdate 00:00:00' AND '$enddate 23:59:00')"; $mssqlquery = mssql_query ($query1, $hocstat_db_connect); while ($row =(mssql_fetch_array($mssqlquery))) { $callcount[] = $row['calls']; } } return $callcount; } }//class close if($_POST) //setting varibles from form input { $shift_id= isset($_POST['shift']) ? trim($_POST['shift']) : die('Missing entry: Shift Selection'); $start_date= isset($_POST['startdate']) ? trim($_POST['startdate']) : die('Missing enty: Start Date'); $end_date= isset($_POST['enddate']) ? trim($_POST['enddate']) : die('Missing enty: End Date'); $depart_id= isset($_POST['department']) ? trim($_POST['department']) : die('Missing entry: Shift Selection'); } echo "You have selected stats for $shift_id shift(s) and $depart_id department(s) from $start_date to $end_date. </br>" ; $test=new DataLogic(); $calls = $test->GetCalls($test->GetEmpNames($test->RepSortShiftDept($test->SelectEmpShift("$shift_id"), $test->SelectEmpDep("$depart_id"))), $start_date, $end_date); $iris= $test->GetIris ($test->RepSortShiftDept($test->SelectEmpShift("$shift_id"), $test->SelectEmpDep("$depart_id")), $start_date, $end_date); $name= $test-> DisplayEmpNames($test->RepSortShiftDept($test->SelectEmpShift("$shift_id"), $test->SelectEmpDep("$depart_id"))); $table = array ( 'calls' => $calls, 'iris' => $iris, 'name' => $name); for ($x = 0; $x < count ($table['calls']); $x++) { echo $table["name"][$x]; echo "</br> Calls Taken :"; echo $table["calls"][$x]; echo "</br> Iris Tickets Resolved:"; echo $table["iris"][$x]; echo "</br>"; } ?> hello i have a mysql table and i want to display each row in a different page with an added condition, the code: Code: [Select] if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = $page-1; $qry="SELECT * FROM ordering WHERE userid='$page' AND email='$email' LIMIT 0,1"; $result = mysql_query($qry); while($row = mysql_fetch_array($result)){ echo "<div dir='rtl' charset='utf8'><h2>"," hover cam: ",$row['hover_camera'], "<br> stills: ",$row['stills'], "<br> video_photographers: ",$row['video_photographers'], "<br> increase: ",$row['increase'], "<br> video_edit: ",$row['video_edit'], "<br> digital_album: ",$row['digital_album'], "<br> photo_album: ",$row['photo_album'], "<br> small_digital_album: ",$row['small_digital_album'], "<br> video_clip: ",$row['video_clip'], "<br> magnets: ",$row['magnets'], "<br> comments: ",$row['comments'], "<br> date: ",$row['date'], "<br><br></h2></div>"; } $sql = "SELECT COUNT(userid) FROM ordering"; $result = mysql_query($sql,$link); $row2 = mysql_fetch_row($result); $total_records = $row2[0]; $total_pages = $total_records ; for ($i=1; $i<=$total_pages; $i++) { echo "<a href='myorders.php?page=".$i."'>".$i."</a> "; }; the table is as so: Code: [Select] CREATE TABLE IF NOT EXISTS `ordering` ( `userid` int(11) unsigned NOT NULL AUTO_INCREMENT, `hover_camera` varchar(10) DEFAULT NULL, `stills` int(5) NOT NULL, `video_photographers` int(5) NOT NULL, `increase` int(5) NOT NULL, `video_edit` varchar(10) NOT NULL, `digital_album` varchar(10) DEFAULT NULL, `photo_album` varchar(10) DEFAULT NULL, `small_digital_album` varchar(20) DEFAULT NULL, `video_clip` varchar(10) DEFAULT NULL, `magnets` int(10) NOT NULL, `comments` text NOT NULL, `date` date NOT NULL, `fname` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, PRIMARY KEY (`userid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; now to the problem: this code displays all the userid as page numbers however, the email condition is good only for part of the rows it's a little hard to explain, i'll try an example: suppose the email '1@1.com' is at rows 22,25 and 30 my code displays 30 page numbers and page 22 is user 22, page 25 is user 25 etc. what i want is to display only the page numbers of the pages with the conditional email, and if possible to display them as 1,2,3 instead of 22,25,30 I'm building a query that searches by database and returns matching (or almost matching) terms. That part isn't the problem- I have it up and working. The problem is that I'm trying to narrow down the search results, and it's not working. Here's the query that works: Code: [Select] $result = mysql_query("SELECT * FROM auctions WHERE name LIKE '%".$searchterm."%' OR Address LIKE '%".$searchterm."%' OR state like '%".$searchterm."%'"); Here's the query that DOESN'T works: Code: [Select] $result = mysql_query("SELECT * FROM auctions WHERE type='Cars' AND name LIKE '%".$searchterm."%' OR Address LIKE '%".$searchterm."%' OR state like '%".$searchterm."%'"); What I'm trying to do is say "give me all the results from type:Cars. Instead, it ignores the WHERE type='Cars' statement, and returns results for all types. It frustrates me because I use the same exact query in a thousand other places, and it works everywhere else. For example: Code: [Select] $sql = "SELECT * FROM auctions WHERE type='Boats' AND state='$v4' ORDER BY $v1 $v2"; works just fine. I'm not exactly an expert on any of this, but I can see no logical reason why this works, but the Search code doesn't. They appear in all ways identical, at least as far as query structure goes. Can anyone spot where I screwed up? Thanks! Kyle This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=351748.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314051.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=342944.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=307094.0 |