PHP - Repeat Query
Similar Tutorialshi, is there a way to tell php to do a process again? example: Code: [Select] $draft_number=rand(1, 15); if($draft_number == 5){ START OVER AT TOP } else { $sql1 = "UPDATE names SET draft = '$draft_number' WHERE id = '$uid'"; $result1 = mysql_query($sql1) or die('Error, Check you fields and try again.'); } I have simple script here that uses curl to post to a few forms and send receive cookies. Now whenever I run the script it takes 10 seconds for the whole process to finish . Is it possible to reduce this time whenever the script is run the second or third.. time. my english is poor , i am having difficulty in putting words to what I want to say... But what I want is for the script to somehow use the previous cookies , detect if they are expired and then do things accordingly(run only the last block of code , if cookie hasn't expired) . How do I go about doing this ? any suggestions ? Thanks The script: Code: [Select] <?php //Create File // $ckfile = tempnam("","testfile.tmp") ; $ckfile = "testFile.tmp"; $ourFileHandle = fopen($ckfile, 'w') or die("can't open file"); fclose($ourFileHandle); //goto home page , to get initial cookies (not required the second time) $ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/falcon.application_start"); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); ////click on enter as guest. and post the info from te form. $ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/Falcon_Users_Cookies.Run_Create"); curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "p_JS=N&p_Anon=ANONYMOUS&p_user_type=Enter as Guest"); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); //open the search page. $ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/Falcon.Search_Screen?p_search_no=0&p_SearchLevel=FULL"); curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); //search on the search page. $ch = curl_init ("http://pericles.ipaustralia.gov.au/atmoss/Falcon.Result"); curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "p_partword_1=nice"); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_exec ($ch); //fclose($ourFileHandle); ?> Also for some reason the cookie file ends up being a zero byte file. any one know why hey guys
Doing last bit of site now and after doing full testing I found 1 little bug that I don't like I created an appointment section with a table to display resuilts from mysql, works great, but add more than 1 appiontment and its almost adding a whole new page See attachment for pic Heres the code for the table <?php echo '<h2>Customer Appointments</h2>'; ?> </span></div><table width="1248" border="3" align="center"> <tr class="new"> <td width="116" class="re" style="text-align: center"><strong>Date Booked</strong></td> <td width="96" class="re" style="text-align: center"><strong class="table">Time Booked</strong></td> <td width="823" class="re" style="text-align: center"><strong class="table">Notes</strong></td> </tr> <?php do { ?> <tr class="table"> <td class="re" style="text-align: center; color: #FFF;"><?php echo $row['datebooked']; ?></td> <td class="re" style="text-align: center"><?php echo $row['timebooked']; ?></td> <td class="re" style="text-align: center"><?php echo $row['notes']; ?></td> </tr> <?php } while ($row = mysql_fetch_assoc($Recordset1)); ?> </table> <span class="re"> <?phpIs there anyway I can make the Titles: Date Booked, Time Booked, Notes and have all results showing directly underneath? Attached Files success.JPG 31.29KB 0 downloads I have a script that opens up a CSV file and outputs to a table for testing. It ultimately inserts into a MySQL but the code below literally duplicates every third row consistently. I'm 95% sure its in the "WHILE" area. Is there enough code here for someone to point out an error. If not I can put the code up live and if you want a fee for fixing just PM me please. Code: [Select] $fp = fopen("residential-data.csv", "r"); $listings=-1; function getZip($full) { $pieces = explode(' ', $full); $zip = explode('(', $pieces[count($pieces)-1]); $zip = explode(')', $zip[1]); return $zip[0]; } $pre=""; while (($data = fgets($fp,4096)) !== FALSE) { $data=str_replace("\r\n","",$data); if(trim($data)=="" or substr($data,strlen($data)-1,1)!='"' or substr($data,strlen($data)-2,2)==',"') { $pre.=$data; } Hi Everyone, could anyone tell me why this only shows one record. There is at least four that will match the query. case 'jayzquotes'; echo '<table border="0" cellspacing="0" cellpadding="2"><tr><td><h1>Jay-Z Quotes</h1></td></tr></table><br>'; echo '<table width="600" border="0" cellspacing="0" cellpadding="2">'; $result = mysql_query("SELECT * FROM quotes WHERE artist LIKE 'J%' and approved = 'y'") or die(mysql_error()); $count = mysql_num_rows ($result ); while($row=mysql_fetch_array($result)){ $resultb = mysql_query("SELECT * FROM comments WHERE quoteid=".$row['quoteid']."") or die(mysql_error()); while($link=mysql_fetch_array($resultb)){ $date = $row[date]; $user = $row[user]; $email = $row[email]; $artist = $row[artist]; $song = $row[song]; $quote = stripslashes($row[quote]); $quoteid = $row[quoteid]; $votes = $row[votes]; echo ' <tr> <td width="424"><strong>Date Submitted:</strong><span class="red"> '.$date.'</span></td> <td width="156" align="right"><strong>Total Votes</strong> (<span class="red">'.$votes.'</span>)</td> </tr> <tr> <td colspan="2"><strong>Quote submitted by:</strong><span class="red"> '.$user.' </span>- <span class="red"><a href="mailto:'.$email.'">'.$email.'</a> </span></td> </tr> <tr> <td colspan="2"><strong>Artist:</strong> <span class="red">'.$artist.' </span></td> </tr> <tr> <td colspan="2"><strong>Song name:</strong> <span class="red">'.$song.' </span></td> </tr> <tr> <td colspan="2"><strong>Quote:</strong><hr></td> </tr> <tr> <td colspan="2">'.$quote.'</td> </tr> <tr> <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="quotefooter"> <tr> <td><strong>(<span class="dark">'.$countb.'</span>) Comments: View / Edit Comments</strong></td> <td align="center"><strong><a href="index.php?action=editquote"eid='.$quoteid.'" target="_self">Edit Quote</a></strong></td> <td align="center"><strong><a href="index.php?action=deletequote"eid='.$quoteid.'">Delete Quote</a></strong></td> </tr> </table><br><hr></td> </tr> '; } } echo '</table>'; echo '<strong>Total Results</strong><span class="red"> '.$count.'</span>'; break; I have this code which checks for the word "Big Ben" and if it's not there it outputs some html. I want t be able to make another statement to also check for the word "London Tower" and if it's not there then to check for the word "Canary Wharf", So far I've only managed one statement without the code breaking, how do I add the others in as well. <?php $astacker=get_post_meta($post->ID, 'thesite', true); if ( $astacker == [b]'Big Ben'[/b]) { ?> <?php include(TEMPLATEPATH."/feedsgrabstack.php");?> <?php }else { ?> <div id="splitter"><div class="clear"> <a href="<?php echo get_post_meta($post->ID, "linktosource", true);?>">Click Here To View Answers</a> <span style="float:right;"><a href="#related">See Related Questions</a></div></div> <?php } ?> Hello, I need help in making my script loop indefinitely. Any ideas? Hey guys, bascially I'm developing a simple news script, and part of it has a "quick news" section, which will display the latest 3 (or any number I want) news items, each seperated by a line (<hr> in the example below). What I want to acheive is the top 2 news items have a set LI class assigned to them, and then the 3rd LI in the list to have a different style attached to it (one without a bottom border basically), so it'll bascially repeate out the normal <li> until it hits the last item to be output, at which point it uses a LI with a class attached to it. What I don't know how to do, is tell the PHP that once it's out putted 2 LI's, then the 3rd LI is to have a different class on it. eg Code: [Select] <li>News Item 1</li> <li>News Item 2</li> <li class="last">News Item 3</li> I'm pretty new to PHP so not sure how to achieve this and would appreicate any help you can offer. Here's my code so far... Code: [Select] <?php $latestnews_sql = "SELECT * FROM news ORDER BY date DESC LIMIT 3"; $latestnews_query = mysql_query($latestnews_sql) or die (mysql_error()); $list_latestnews = mysql_fetch_assoc ($latestnews_query); ?> <ul> <?php do { ?> <li><p><strong><?php echo $list_latestnews['title']; ?></strong></p> <?php echo substr($list_latestnews['body'],0,80)."...";?> <a href="news-detail.php?ID=<?php echo $list_latestnews['ID']; ?>">view more</a></p> <p><span style="font-size:13px; font-style:italic;"><?php echo $list_latestnews['author']; ?> - <?php echo date("l, jS F Y", strtotime($list_latestnews['date'])); ?></span></p> <hr /> </li> <?php } while ($list_latestnews = mysql_fetch_assoc ($latestnews_query)) ?> </ul> i want to fetch contributors in adding certain articles... so its like select contributors from table where id=id the table looks like this. title contributor ---------------------------------- art1 me art2 me art3 you art4 me art5 you I then need to echo the contributors... what do i do so that it echoes one name only once, no duplicates... thanks. I tried searching google but im not sure about my keywords I was hard code to make if condition until like seem. But its to hard to write. if ($lebar == 41) { $x = 1; } else if ($lebar == 42) { $x = 2; } else if ($lebar == 43) { $x = 3; } else if ($lebar == 44) { $x = 4; } else if ($lebar == 45) { $x = 5; ..... } else if ($lebar == 490) { $x = 450; } How to make it simple with looping or any clue? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=316681.0 How do you make php code repeat for a certain amount of times. I am only new to php and I am trying to make the code below repeat 6 times instead of repeating all the matching elements in the database. From my other coding experience I would use a for loop but as I am new to php I am not really sure how to implement the for and while loops together. I was trying to add an integer that incremented until it hit 6 and then would exit the while loop but I couldn't get it to work. This is probably a simple problem and any help would be appricated. Thanks. Code: [Select] <?php $subject_set = mysql_query("Select * FROM movies WHERE media = 'Movies' ORDER BY dateadded DESC", $connection); if (!$subject_set){ die("Database connection failed: " . mysql_error()); } while ($subject = mysql_fetch_array($subject_set)){?> <div class="par_element"> <div class="repeat_horizontal"> <div class="repeat_hor_picture"> <a href="<?=$subject['link']?>"> <img src=" <?=$subject['picture']?>" /></a> </div> <a href=" <?=$subject['link']?>"><?= $subject['title']?>.</a> </div> <?php } ?> Hi, i m new with php programming... I m working on one form in which i have created filter options for filter dynamic table content by completed, approve and rejected status.... but problem is when i m selecting any filtered option using select list data is displayed... but when i m clicking on next button in paging... dynamic table showing blank... same slect list getting blank.... anyone will help me...? code of php file Code: [Select] <?php require_once('../Connections/localhost.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } $MM_authorizedUsers = "client"; $MM_donotCheckaccess = "false"; // *** Restrict Access To Page: Grant or deny access to this page function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { // For security, start by assuming the visitor is NOT authorized. $isValid = False; // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. // Therefore, we know that a user is NOT logged in if that Session variable is blank. if (!empty($UserName)) { // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. // Parse the strings into arrays. $arrUsers = Explode(",", $strUsers); $arrGroups = Explode(",", $strGroups); if (in_array($UserName, $arrUsers)) { $isValid = true; } // Or, you may restrict access to only certain users based on their username. if (in_array($UserGroup, $arrGroups)) { $isValid = true; } if (($strUsers == "") && false) { $isValid = true; } } return $isValid; } $MM_restrictGoTo = "../index.php"; if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) { $MM_qsChar = "?"; $MM_referrer = $_SERVER['PHP_SELF']; if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) $MM_referrer .= "?" . $_SERVER['QUERY_STRING']; $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); header("Location: ". $MM_restrictGoTo); exit; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $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; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset1 = 30; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $myID = $_SESSION['MM_Username']; $mystatus=$_GET['status']; switch ($options) { case "All"; $All="selected"; break; case "Completed"; $Completed="selected"; break; case"Rejected"; $Rejected="selected"; break; case"Pending"; $Pending="selected"; break; } $mystatus=$_POST['status']; $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; //databse queary for filters $query_Recordset1 = "SELECT username, Jobid, Market, General_10, Entry_Points, Dept_Points, General_Points, Total_Points FROM form_gf "; if($mystatus !=='All'){ $query_Recordset1 .= "WHERE status = '$mystatus'";} else { $query_Recordset1 .= "ORDER BY form_gf.Jobid";} mysql_select_db($database_localhost, $localhost); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $localhost) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; mysql_select_db($database_localhost, $localhost); $query_status = "SELECT dropdown.options FROM dropdown WHERE dropdown.dropdownname = 'status'"; $status = mysql_query($query_status, $localhost) or die(mysql_error()); $row_status = mysql_fetch_assoc($status); $totalRows_status = mysql_num_rows($status);mysql_select_db($database_localhost, $localhost); $query_status = "SELECT options FROM dropdown WHERE dropdownname = 'status' ORDER BY options ASC"; $status = mysql_query($query_status, $localhost) or die(mysql_error()); $row_status = mysql_fetch_assoc($status); $totalRows_status = mysql_num_rows($status); $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?> <!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>Brakedown Report</title> <link href="../template.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="../Menu/js/jquery.js"></script> <script type="text/javascript" src="../Menu/js/interface.js"></script> <script type="text/javascript" src="../Menu/js/fisheye_patched.js"></script> <!--[if lt IE 7]> <style type="text/css"> .dock img { behavior: url(iepngfix.htc) } </style> <![endif]--> <link href="../Menu/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .Header { font-family: "Segoe UI"; font-size: 12px; font-weight: 500; color: #CCC;} .table { font-family: "Segoe UI"; font-size: 10pt; border: 1px solid #000; } .text { font-family: "Segoe UI"; font-size: 10pt; } a { font-family: "Segoe UI"; font-size: 12px; color: #333; font-weight: bold; } a:link { text-decoration: none; } a:visited { text-decoration: none; color: #333; } a:hover { text-decoration: none; color: #36F; } a:active { text-decoration: none; color: #333; } </style> </head> <body> <!--Wrapper Start--> <div id="wrapper"> <!--Header Start--> <div id="header"> <div id="logo"><img src="../images/logo.png" alt="isnlogo" width="64" height="30" align="middle" longdesc="http://www.isngs.com" /></div> <div id="userinfo"> <table width="180" border="0" align="right" cellpadding="0" cellspacing="0"> <tr> <td width="27" height="34"><img src="../images/user.png" width="26" height="30" alt="user" /></td> <td width="77">Sagar Dhande</td> <td width="26"><img src="../images/arrow.png" width="26" height="30" alt="arrow" /></td> </tr> </table> </div> <div id="status"></div> </div> <!--Header end--> <div id="content"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr align="center"> <td width="99%"> <div id="dash3"> <div id="dash3_grid_head">Total Reccords </div> <div id="dash3_grid_cont_back"><br /> <table width="890" border="0" align="center" cellpadding="0" cellspacing="0" class="table"> <tr class="Header"><form action="" method="post"> <td height="55" colspan="3" align="center" valign="middle" id="filters">Filter By Status</td> <td align="left" valign="middle"><select name="status" id="status2" onchange="document.forms[0].submit();"> <option value="" <?php if (!(strcmp("", $mystatus))) {echo "selected=\"selected\"";} ?>></option> <?php do { ?> <option value="<?php echo $row_status['options']?>"<?php if (!(strcmp($row_status['options'], $mystatus))) {echo "selected=\"selected\"";} ?>><?php echo $row_status['options']?></option> <?php } while ($row_status = mysql_fetch_assoc($status)); $rows = mysql_num_rows($status); if($rows > 0) { mysql_data_seek($status, 0); $row_status = mysql_fetch_assoc($status); } ?> </select></td> <td align="left" valign="bottom"><a href="excel.php"></a></td> <td align="left" valign="bottom"> </td> <td align="center" valign="middle"><a href="../excelexprt.php"></a></td> <td align="center" valign="middle"> </td> <td align="center" valign="middle"> </td> <td align="right" valign="middle"><a href="excel.php"><img src="../images/Export.png" alt="Export" width="48" height="48" border="0" /></a></td> </form> </tr> <tr class="Header"> <td height="2" colspan="10" align="center" valign="bottom" id="filters3"><hr color="#333333" size="1px"/></td> </tr> <tr class="Header"> <td height="345" colspan="10" align="center" valign="bottom" id="filters"><a href="../excelexprt.php"> <iframe src="pai1.php" width="485px" height="370px" frameborder="0"></iframe> </a></td> </tr> <tr class="Header"> <td height="22" colspan="3" align="center" valign="bottom" id="filters2"> </td> <td align="left" valign="bottom"> </td> <td align="left" valign="bottom"> </td> <td align="left" valign="bottom"> </td> <td colspan="4" align="center" valign="middle"> </td> </tr> <tr class="Header"> <td style="border: 1px solid #000;" height="44" colspan="3" align="center" valign="middle" bgcolor="#666666">Options</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666" class="Header">Job ID</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Market ID</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Transaction No.</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Entry Points</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Department Points</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">General Points</td> <td style="border: 1px solid #000;" width="100" align="center" valign="middle" bgcolor="#666666">Total Points</td> </tr> <?php do { ?> <tr> <td width="31" height="28" align="center" style="border: 1px solid #000;"><a href="../pdf.php?Jobid=<?php echo $row_Recordset1['Jobid']; ?>" target="_blank"><img src="../images/pdf.png" alt="PDF Export" width="16" height="16" border="0" /></a></td> <td width="31" style="border: 1px solid #000;" align="center"><a href="../view.php?Jobid=<?php echo $row_Recordset1['Jobid']; ?>" target="_blank"><img src="../images/preview.png" alt="Preview" width="16" height="16" border="0" /></a></td> <td width="31" style="border: 1px solid #000;" align="center"><a href="../update_form.php?Jobid=<?php echo $row_Recordset1['Jobid']; ?>" target="_blank"><img src="../images/Edit.png" alt="Edit" width="16" height="16" border="0" /></a></td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Jobid']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Market']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['General_10']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Entry_Points']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Dept_Points']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['General_Points']; ?> </td> <td style="border: 1px solid #000;" align="right"><?php echo $row_Recordset1['Total_Points']; ?> </td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> <table border="0" align="center" width="270px"> <tr> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="../images/first.png" alt="First" width="16" height="16" alt="First Page" /> </a> <?php } // Show if not first page ?></td> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="../images/previous.png" alt="Previous Page" width="16" height="16" alt="previous" /> </a> <?php } // Show if not first page ?></td> <td width="150px" style="font-family:'Segoe UI'; font-size:12px; color:#333; font-weight:700; line-height:40px;"> Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?></td> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="../images/Next.png" width="16" height="16" alt="Next" /> </a> <?php } // Show if not last page ?></td> <td width="30px" valign="middle"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="../images/Last.png" alt="Last Page" width="16" height="16" alt="Last" /> </a> <?php } // Show if not last page ?></td> </tr> </table> </table> </div> <div id="dash3_grid_bot"></div> </div><br /> <br /> <br /> </td> </tr> </table> <div id="dashboard"> </div> </div> <div class="dock" id="dock2"> <div class="dock-container2"> <a class="dock-item2" href="client.php"><span>Dashboard</span><img src="../Menu/images/Dashboard-.png" alt="home" /></a> <a class="dock-item2" href="brakedown.php"><span>Brakedown Report</span><img src="../Menu/images/brakedown.png" alt="contact" /></a> <a class="dock-item2" href="Compliance.php"><span>Compliance Report</span><img src="../Menu/images/compliance.png" alt="portfolio" /></a> <a class="dock-item2" href="jobstatus.php"><span>Job Status Report</span><img src="../Menu/images/jobstatus.png" alt="music" /></a> <a class="dock-item2" href="reports.php"><span>Reports</span><img src="../Menu/images/charts.png" alt="video" /></a> <a class="dock-item2" href="#"><span>Logout</span><img src="../Menu/images/off.png" alt="history" /></a> </div> </div> <!--Menu End--> </div> <!--Wrapper End--> <!--dock menu JS options --> <script type="text/javascript"> $(document).ready( function() { $('#dock2').Fisheye( { maxWidth: 60, items: 'a', itemsText: 'span', container: '.dock-container2', itemWidth: 40, proximity: 80, alignment : 'left', valign: 'bottom', halign : 'center' } ) } ); </script> </body> </html> <?php mysql_free_result($Recordset1); mysql_free_result($status); ?> Please Help me guys I am trying to create a order history page. I want it to look something like this: Ordernumber: 12 Products: Product 1 Product 2 Product 3 Product 4 Total: xx Ordernumber: 13 Products: Product 5 Product 6 Total: xx and so on. I have a recordset which get the ordernumbers from my database and i have another recordset which get the products (this recordset has a WHERE clause which is used to get the products associated with its ordernumber. Code: [Select] mysql_select_db($database_lol, $lol); $query_ono = "SELECT DISTINCT ordre.ono FROM ordre WHERE ordre.bruker='{$_SESSION['MM_Username']}'"; $ono = mysql_query($query_ono, $lol) or die(mysql_error()); $row_ono = mysql_fetch_assoc($ono); $totalRows_ono = mysql_num_rows($ono); mysql_select_db($database_lol, $lol); $query_history = "SELECT ordre.vare FROM ordre WHERE ordre.ono='{$row_ono['ono']}'"; $history = mysql_query($query_history, $lol) or die(mysql_error()); $row_history = mysql_fetch_assoc($history); $totalRows_history = mysql_num_rows($history); This is the recordsets. this is my table: +-------+---------------------+------+ | ID | vare | ono | +-------+---------------------+------+ | 1 | Product 1 | 12 | | 2 | Product 2 | 12 | | 3 | Product 3 | 12 | | 4 | Product 4 | 12 | | 5 | Product 5 | 13 | | 6 | Product 6 | 13 | +-------+---------------------+------+ So my question is: How do i do this? list all the records i mean. Thanks Hello all,
Based on the suggestion of you wonderful folks here, I went away for a few days (to learn about PDO and Prepared Statements) in order to replace the MySQLi commands in my code. That's gone pretty well thus far...with me having learnt and successfully replaced most of my "bad" code with elegant, SQL-Injection-proof code (or so I hope).
The one-and-only problem I'm having (for now at least) is that I'm having trouble understanding how to execute an UPDATE query within the resultset of a SELECT query (using PDO and prepared statements, of course).
Let me explain (my scenario), and since a picture speaks a thousand words I've also inlcuded a screenshot to show you guys my setup:
In my table I have two columns (which are essentially flags i.e. Y/N), one for "items alreay purchased" and the other for "items to be purchased later". The first flag, if/when set ON (Y) will highlight row(s) in red...and the second flag will highlight row(s) in blue (when set ON).
I initially had four buttons, two each for setting the flags/columns to "Y", and another two to reverse the columns/flags to "N". That was when I had my delete functionality as a separate operation on a separate tab/list item, and that was fine.
Now that I've realized I can include both operations (update and delete) on just the one tab, I've also figured it would be better to pare down those four buttons (into just two), and set them up as a toggle feature i.e. if the value is currently "Y" then the button will set it to "N", and vice versa.
So, looking at my attached picture, if a person selects (using the checkboxes) the first four rows and clicks the first button (labeled "Toggle selected items as Purchased/Not Purchased") then the following must happen:
1. The purchased_flag for rows # 2 and 4 must be switched OFF (set to N)...so they will no longer be highlighted in red.
2. The purchased_flag for row # 3 must be switched ON (set to Y)...so that row will now be highlighted in red.
3. Nothing must be done to rows # 1 and 5 since: a) row 5 was not selected/checked to begin with, and b) row # 1 has its purchase_later_flag set ON (to Y), so it must be skipped over.
Looking at my code below, I'm guessing (and here's where I need the help) that there's something wrong in the code within the section that says "/*** loop through the results/collection of checked items ***/". I've probably made it more complex than it should be, and that's due to the fact that I have no idea what I'm doing (or rather, how I should be doing it), and this has driven me insane for the last 2 days...which prompted me to "throw in the towel" and seek the help of you very helpful and intellegent folks. BTW, I am a newbie at this, so if I could be provided the exact code, that would be most wonderful, and much highly appreciated.
Thanks to you folks, I'm feeling real good (with a great sense of achievement) after having come here and got the great advice to learn PDO and prepared statements.
Just this one nasty little hurdle is stopping me from getting to "end-of-job" on my very first WebApp. BTW, sorry about the long post...this is the best/only way I could clearly explaing my situation.
Cheers guys!
case "update-delete": if(isset($_POST['highlight-purchased'])) { // ****** Setup customized query to obtain only items that are checked ****** $sql = "SELECT * FROM shoplist WHERE"; for($i=0; $i < count($_POST['checkboxes']); $i++) { $sql=$sql . " idnumber=" . $_POST['checkboxes'][$i] . " or"; } $sql= rtrim($sql, "or"); $statement = $conn->prepare($sql); $statement->execute(); // *** fetch results for all checked items (1st query) *** // $result = $statement->fetchAll(); $statement->closeCursor(); // Setup query that will change the purchased flag to "N", if it's currently set to "Y" $sqlSetToN = "UPDATE shoplist SET purchased = 'N' WHERE purchased = 'Y'"; // Setup query that will change the purchased flag to "Y", if it's currently set to "N", "", or NULL $sqlSetToY = "UPDATE shoplist SET purchased = 'Y' WHERE purchased = 'N' OR purchased = '' OR purchased IS NULL"; $statementSetToN = $conn->prepare($sqlSetToN); $statementSetToY = $conn->prepare($sqlSetToY); /*** loop through the results/collection of checked items ***/ foreach($result as $row) { if ($row["purchased"] != "Y") { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToY = $statementSetToY->fetch(); foreach($resultSetToY as $row) { $statementSetToY->execute(); } } else { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToN = $statementSetToN->fetch(); foreach($resultSetToN as $row) { $statementSetToN->execute(); } } } break; }CRUD Queston.png 20.68KB 0 downloads Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> Say I have this query: site.com?var=1 ..I have a form with 'var2' field which submits via get. Is there a way to produce: site.com?var=1&var2=formdata I was hoping there would be a quick way to affix, but can't find any info. Also, the query could sometimes be: site.com?var2=formdata&var=1 I would have to produce: site.com?var2=updatedformdata&var=1 Is my only option to further parse the query? I was just wondering if it's possible to run a query on data that has been returned from a previous query? For example, if I do Code: [Select] $sql = 'My query'; $rs = mysql_query($sql, $mysql_conn); Is it then possible to run a second query on this data such as Code: [Select] $sql = 'My query'; $secondrs = mysql_query($sql, $rs, $mysql_conn); Thanks for any help I'm trying to update every record where one field in a row is less than the other. The code gets each row i'm looking for and sets up the query right, I hope I combined the entire query into one string each query seperated by a ; so it's like UPDATE `table` SET field2= '1' WHERE field1= '1';UPDATE `table` SET field2= '1' WHERE field1= '2';UPDATE `table` SET field2= '1' WHERE field1= '3';UPDATE `table` SET field2= '1' WHERE field1= '4';UPDATE `table` SET field2= '1' WHERE field1= '5'; this executes properly if i run the query in phpMyAdmin, however when I run the query in PHP, it does nothing... Any advice? |