PHP - Loop Through Returned Records From Query
Have a web page that displays a number of update forms depending on the amout of records that get returned from a mysql query, if query returns 4 records then the page will display 4 identical forms, the trouble i'm having is getting the each of the 4 forms to display a different record as at the moment they all show just first record of query.
I have played around with loops but not getting anywhere which may be due to my limited knowledge code for page is below Code: [Select] <?php $numberofrow =mysql_num_rows($Recordset1); for($counter = 1;$counter<=$numberofrow;$counter++){ ?> <label for="hometeam2"></label> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <label for="hometeam"></label> <input name="fixid" type="text" id="fixid" value="<?php echo $row_Recordset1['FixtureID']; ?>" /> <input name="hometeam" type="text" id="hometeam2" value="<?php echo $row_Recordset1['hometeamname']; ?>" /> <label for="homescore"></label> <input name="homescore" type="text" id="homescore" value="<?php echo $row_Recordset1['homescore']; ?>" /> <label for="awayscore"></label> <label for="fixid"></label> <input name="awayscore" type="text" id="awayscore" value="<?php echo $row_Recordset1['awayscore']; ?>" /> <label for="awayteam"></label> <input name="awayteam" type="text" id="awayteam" value="<?php echo $row_Recordset1['awayteamname']; ?>" /> <input type="submit" name="update" id="update" value="Submit" /> <input type="hidden" name="MM_update" value="form1" /> Similar TutorialsAm currently using this code, and actually thinking about it should split the query to an include in order to allow for other database drivers, on the chance we may decide to ditch the old MySQL. But I digress from the question. Code: [Select] include($lib."dbconfig.php"); $q = 'SELECT * FROM file WHERE this = "'.$that'"; $result = mysql_query($q); if (mysql_num_rows($result) > 0) If the query doesn't pick up a row I'm getting this error yo, Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\webpages\*\*\admin.php on line 553 So what would be a better way of testing if the query was successful? I'm trying to develop some php that will execute a MySQL query and move the results into XML. In this particular instance, only one record is expected to be returned, and that one row will contain all the customer data, such as last name, first name, address1, etc. While I can get my code to work and create the xml if I hard-code in all the keys (MySQL column names), I would like it to dynamically step through all the keys/MySQL column names so that if the db changes later (add more columns, for instance) the code generating the XML won't need to be altered. It should take the MySQL column name, create an element based on the column name, then create a text node and insert the value. Currently I'm just at the spot of testing by echoing the appropriate key/value pairs. The code is stopping after the first key/value without going through the rest of the columns. What do I need to do in order to get it to dynamically step through each column and get the key/value? Here's the relevant code: if($_POST['buscode']) {echo "buscode is: ".$_POST['buscode']."<HR>";} else {echo "ERROR WITH RETRIEVING BUSCODE<HR>";} $buscode = $_POST['buscode']; $query = "SELECT * " ."FROM customers " ."WHERE buscode = '$buscode'"; echo "Query will be: ".$query."<HR>"; $result = mysql_query($query); if($result){echo "Success retrieving data from ats_ajax.<HR>";} else{echo "Error retrieving data from ats_ajax\; MySQL error is:".mysql_error($result)."<HR>";} //////////////////////////////////////// // Let's test getting the keys and values from the array.... /////////////////////////////////////// while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "This is step ".$i."<BR>"; $key = key($row); echo "Key is: ".$key."<BR>"; echo "Value is: ".$row[$key]."<BR>"; $i++; }//close of while Hello folks,
In trying to improve the user experience for my first WebApp I have decided to create two new tables - one a master file to contain a list of all stores, and the second a master file to contain a list of all products that are normally purchased - and I would like to use the values from these two tables as lookup values in dropdown listboxes, to which the user can also add new entries.
As it turns out, I'm stuck on the very first objective i.e. to lookup/pull-in the distinct values from the master tables.
The problem I'm having is that the query seems to return no rows at all...in spite of the fact that there a records in the table, and the exact same query (when run within the MySQL environment) returns all the rows correctly.
Is there something wrong with my code, or how can I debug to see whether or not the query is being executed?
Objective # 2, which is to allow new values to be entered into the dropdown listbox, and then inserted into the respective table is certainly waaay beyond my beginner skills, and I'll most certainly need to some help with that as well..so if I can get some code/directions in that regard it will be most appreciated.
Thank you.
<?php $sql = "SELECT DISTINCT store_name FROM store_master ORDER BY store_name ASC"; $statement = $conn->prepare($sql); $statement->execute(); $count = $statement->rowCount(); echo $count; // fetch ALL results pertaining to the query $result = $statement->fetchAll(); echo "<select name=\"store_name\">"; echo '<option value="">Please select...</option>'; foreach($result as $row) { echo "<option value='" . $row['store_name'] . "'></option>"; } echo "</select>"; ?> Search not functioning. The drop down box to search on Club_Name and Email is blank, clicking search results unchanged ... all suggestions appreciated ... newbie at php. Thanks. <!-- Code below is not functional, trying to query search results, search box with drop down box for two fields--> <table width="50%"> <tr> <td height="30" align="left" bgcolor="#FFFFFF" class="form1" > {$letter_links} </td> <td height="30" align="right" bgcolor="#FFFFFF" class="form1" > <input type=hidden name="sorter" value="{$sorter}"> <table><tr> <form name="search_form" action="{$form.action}" method="post"> <td class="form1" ><input type="text" name="search" value="{$search}"></td> <td class="form1" ><select name="s_type" style=""> {section name=s loop=$types} <option value="{$smarty.section.s.index_next}" {if $types .sel}selected{/if}>{$types .value}</option> {/section} </select></td> <td class="form1"><input type="button" value="{$button.search}" class="button" onclick="javascript: document.search_form.submit();" name="search_submit"></td> </form> </tr></table> </td> </tr> </table> <!-- Code below successfully displays query results --> <form method="post" action="{$file_name}?sel=approve" enctype="multipart/form-data" name="form1" onsubmit="foo(); return false;"> <table cellspacing="2" cellpadding="10" border="1"> <tr align="center"><td>Num</td><td>Club Name</td><td>Login</td><td>Country</td><td>Region</td><td>City</td><td>Address</td><td>Web site</td><td>Email</td><td>Contact Name</td><td>Contact Phone</td><td>Swinging</td><td>Alcohol</td><td>Food</td><td>Entertainment</td><td>Fees</td><td>Approved/<br/>Rejected</td><td>Actions</td></tr> {foreach item=item from=$contest key=key name=foo} <tr align="center"><td><input type="hidden" name="all_approves[{$item.id}]" value="{$item.id}"/>{$key+1}</td><td>{$item.name}</td><td>{$item.login}</td><td>{$item.country_name}</td><td>{$item.region_name}</td><td>{$item.city_name}</td><td>{$item.address}</td><td>{$item.web_site}</td><td>{$item.email}</td><td>{$item.contact_name}</td><td>{$item.contact_phone}</td> <td> {math equation="x - 1" x=$item.swinging assign=index_pos} {$xml_swing[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.alcohol assign=index_pos}{$xml_alco[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.foot assign=index_pos}{$xml_foot[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.entertainment assign=index_pos}{$xml_entertainment[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.fees assign=index_pos}{$xml_fees[$index_pos].value}</td><td> <span> {if $item.is_approved eq '1'} Approved {else} Rejected {/if}</span></td><td align="center"><a href="{$file_name}?sel=edit&id_content={$item.id}">[ Edit ]</a><br/><a href="{$file_name}?sel=delete&id_content={$item.id}">[ Delete ]</a><br/><a href="{$file_name}?sel=approve&id_content={$item.id}">[ Approve ]</a><br/><a href="{$file_name}?sel=reject&id_content={$item.id}">[ Reject ]</a></tr> {/foreach} </table> </form> Say I do a query from a database that only asks for one field in return (which always has a number in it). How do you write the PHP to take the first number returned and add it to the next number returned (NOTE: There may be more than two numbers returned, but for now, I'm always dealing with two) For example, say I do a query that returns the number 27 first and then the number 10 second. FYI, these numbers will be available in the variable $diff['result']. So the code after the query would look something like this, but obviously i'm struggling with the part in comments... Code: [Select] if (!$numbers) { die("Database query failed: " . mysql_error()); } else { while ($diff = mysql_fetch_array($numbers)) { //this would bring back 27 first, in the variable $diff['result'] and then on the 2nd loop through, it would bring back 10 in the $diff['result'] variable //ultimately, i just want the difference between the numbers (which in the case would be 17). It's just a simple addition, so Im obviously an idiot because I can't figure out the syntax for adding the first returned number to the next returned number:) } } here is my code... please help <form method="get" action="shit3.php"> <input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="SEARCH"> </form> <?php if (@$_GET['q']) { $var = $_GET['q'] ; $trimmed = trim($var); $limit=1; if ($trimmed == "") { echo "Please enter a search..."; exit; } if (!isset($var)) { echo "Container not found!"; exit; } mysql_connect("localhost", "xxx", "yyy") or die(mysql_error()); mysql_query("SET NAMES 'cp1251'"); mysql_select_db("agaexpor_container") or die("Unable to select database"); //select which database we're using $query = "select * from containertracking where vin like \"%$trimmed%\" order by vin"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); $count = 1 + $s ; while ($row= mysql_fetch_array($result)) { $vin = $row["vin"]; $container = $row["container"]; echo "$count.) VIN: $vin <br />"; echo "container is: $container <br />"; $count++ ; } } ?> I'm hoping this is a simple question. When I use the code below, my twitter search query appears in BOLD within the returned results. I would like to style the search term differently. I can use CSS to style the avatar, author, and other information within the returned results etc, but I can't figure out how to style the search term ($q) within the returned twitter information. Any help would be much appreciated. <?php class twitter_class { function twitter_class() { $this->realNamePattern = '/\((.*?)\)/'; $this->searchURL = 'http://search.twitter.com/search.atom?lang=en&q='; $this->intervalNames = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year'); $this->intervalSeconds = array( 1, 60, 3600, 86400, 604800, 2630880, 31570560); $this->badWords = array('somebadword', 'anotherbadword'); } function getTweets($q, $limit=15) { $output = ''; // get the search result $ch= curl_init($this->searchURL . urlencode($q)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $response = curl_exec($ch); if ($response !== FALSE) { $xml = simplexml_load_string($response); $output = ''; $tweets = 0; for($i=0; $i<count($xml->entry); $i++) { $crtEntry = $xml->entry[$i]; $account = $crtEntry->author->uri; $image = $crtEntry->link[1]->attributes()->href; $tweet = $crtEntry->content; // skip tweets containing banned words $foundBadWord = false; foreach ($this->badWords as $badWord) { if(stristr($tweet, $badWord) !== FALSE) { $foundBadWord = true; break; } } $tweet = str_replace('<a href=', '<a target="_blank" href=', $tweet); // skip this tweet containing a banned word if ($foundBadWord) continue; // don't process any more tweets if at the limit if ($tweets==$limit) break; $tweets++; // name is in this format "acountname (Real Name)" preg_match($this->realNamePattern, $crtEntry->author->name, $matches); $name = $matches[1]; // get the time passed between now and the time of tweet, don't allow for negative // (future) values that may have occured if server time is wrong $time = 'just now'; $secondsPassed = time() - strtotime($crtEntry->published); if ($secondsPassed>0) { // see what interval are we in for($j = count($this->intervalSeconds)-1; ($j >= 0); $j--) { $crtIntervalName = $this->intervalNames[$j]; $crtInterval = $this->intervalSeconds[$j]; if ($secondsPassed >= $crtInterval) { $value = floor($secondsPassed / $crtInterval); if ($value > 1) $crtIntervalName .= 's'; $time = $value . ' ' . $crtIntervalName . ' ago'; break; } } } $output .= ' <div class="tweet"> <div class="avatar"> <a href="' . $account . '" target="_blank"><img src="' . $image .'"></a> </div> <div class="message"> <span class="author"><a href="' . $account . '" target="_blank">' . $name . '</a></span>: ' . $tweet . '<span class="time"> - ' . $time . '</span> </div> </div>'; } } else $output = '<div class="tweet"><span class="error">' . curl_error($ch) . '</span></div>'; curl_close($ch); return $output; } } ?> The HTML I have been using with this code is here Code: [Select] <!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> <title>Twitter</title> </head> <body> <?php require('twitter.class.php'); $twitter = new twitter_class(); echo $twitter->getTweets('example search term', 10); ?> </body> </html> This is not my code. It is from a tutorial that can be accessed from here >> http://www.richnetapps.com/php-twitter-search-parser/ Hi, I was thinking of creating a table for this current code and place only 3 options in a row, however I do not know how to execute a command which will allow me to do so, I have attached 2 pictures to describe what I will like to achieve. Below is my code as well. Any advice? Thanks $query = ("SELECT * FROM tutor_preferred_district ORDER BY district_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysql_error()); while($data = mysqli_fetch_array($sql)) { echo'<table>'; echo '<input name="district" type="checkbox" id="'.$data['district_id'].'" value="'.$data['district_id'].'">'; echo '<label for="'.$data['district_id'].'">'.$data['district_name'].'</label>'; echo'<table>'; } I've got query. Hi all, I'm trying to make a query that allows the user to edit the name of a entry in SQL. I believe I have the corect Syntax but I'm not sure if I have the code set up correctly. I am using 2 queries when I think it is possible with one. The first query is used to Pint out results for a certain year and the second to update the names. Code: [Select] $desiredYear = $_POST['year']; $nameEdit = $_POST['edit']; $origName = $_POST['orig']; echo ' The year you have chosen is '.$desiredYear; $describeQuery = "SELECT ID, Name, (SELECT SUM(SalesVolume) as SalesVolume FROM MonthlySales WHERE ProductCode=Products.ID AND Year = '$desiredYear') AS num_sales FROM Products"; $editQuery = "UPDATE Products SET Name = '$nameEdit' WHERE Name ='$origName'"; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Sales</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['Name'].'</td>'; echo '<td>' .$row['ID'].'</td>'; echo '<td>' .$row['num_sales'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Can somebody help me with this? Thank you Hello just wondering if someone can help me... I have a select multiple form that sends the id numbers of records I want to get... how do I construct the query to the mysql db to do this? $array-$_POST['form-array'] so something like $r = ("SELECT column from 'Table' WHERE ID = (array, values, here)") Thanks for any help. When I run this query to exclude records where id = $userarray['id'], $q = "SELECT * FROM users WHERE inst_id = '". $userarray['inst_id'] ."' AND id != '". $userarray['id'] ."' "; it actually ONLY returns records with $userarray['id'] as opposed to excluding them. Isn't the way to exclude them to use != ? Hi there, hope have some help. I have a form where a user select time and days of the week (monday, tuesday..) that he is available. The insert script works fine, it insert and the days of week he checked in the table, the only problme is when i try to update each of them.
I used this code above, but is not working, instead of updating/inserting days that is selected is inserting multi-records with the same day of the week value.
here it is:
foreach($weekDay as $DaysofWeek){ $sql_days = "UPDATE available SET day_time = '$day_time', week_day = '$DaysofWeek' WHERE user_id = '$id_user'"; $update_availability = mysql_query($sql_days); } can anybody tell me what's wrong with my query ? $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC"; I am using this in while loop with ps_pagination class but getting 2 records for same set of files. in other words its running while loop 2 time complete code is here... $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel FROM ibwf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC"; $pager = new PS_Pagination($conn, $filesa, 9, 5, $albumid, $sortid, $sub, $selectalbum3[uid], $title, $collective); $results = $pager->paginate(); while($files=mysql_fetch_array($results)) { // Blah Blah } Output is something like this 1. song 1 2. song 2 3. song 3 4. song 4 1. song 1 2. song 2 3. song 3 4. song 4 Thanks is advance Hello guys, I have an website where I have 5 category blocks in my index page to show last 3 posts in each category. But I having problems showing the content in my "last added" block. Sometimes works, and sometimes not. Dont know what is happening... Look: http://screensnapr.com/e/Zm4ssA.jpg Only "Filmes" is showing, but not "Series"... the movies block sometimes have this issue too... the code is almost the same as above, maybe is the same problem... For each category that I want to show their posts, I have a file called newhome_x.php In my templates/dirvideo/main.tpl file, I have this code: Code: [Select] <div id="page_content" class="clearfix"> {info} {newhome_final} {content} </div> In my templates/dirvideo/newhome.tpl file, I have this code: Code: [Select] <li style="margin-right: 45px;" onclick="window.location='{link}'"> <a title='{home_title}' href="{link}"><img src="[xfvalue_poster]" alt='{home_title}' /></a> <h3 style="overflow:hidden"><a title='{home_title}' href="{link}">{home_title}</a></h3> </li> in my index.php I have this code: require_once ENGINE_DIR . '/modules/newhome.php'; require_once ENGINE_DIR . '/modules/newhome_b.php'; require_once ENGINE_DIR . '/modules/newhome_c.php'; require_once ENGINE_DIR . '/modules/newhome_d.php'; require_once ENGINE_DIR . '/modules/newhome_e.php'; if (clean_url ( $_SERVER['HTTP_HOST'] ) != clean_url ( $config['http_home_url'] )) { $replace_url = array (); $replace_url[0] = clean_url ( $config['http_home_url'] ); $replace_url[1] = clean_url ( $_SERVER['HTTP_HOST'] ); } else $replace_url = false; if (!$is_logged && !in_array($_GET['do'], array('register', 'lostpassword'))) { include 'index.html'; die; } $tpl->load_template ( 'main.tpl' ); $tpl->set ( '{lastusers}', $lastusers); $tpl->set('{forumStyle}', require_once ROOT_DIR . '/engine/bullet_energy/modules/load_style.php'); require_once ENGINE_DIR . '/modules/3news.php';$source = '<div class="index_top1" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/movies.gif"> </span> <ul class="clearfix"> {newhome} </ul> </div> <div class="index_top2" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/serie.gif"> </span> <ul class="clearfix"> {newhome_b} </ul> </div> <div class="index_top3" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/music.gif"> </span> <ul class="clearfix"> {newhome_c} </ul> </div> <div class="index_top6" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/jogo.gif"> </span> <ul class="clearfix"> {newhome_e} </ul> </div> <div class="index_top4" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/programas.gif"> </span> <ul class="clearfix"> {newhome_d} </ul> </div>'; if (!isset($_REQUEST["catalog"]) && !isset($_REQUEST["newsid"]) && !isset($_REQUEST["do"]) && !isset($_REQUEST["page"]) && !isset($_REQUEST["category"]) && !isset($_REQUEST["cat"]) && !isset($_REQUEST["action"]) && !isset($_REQUEST["id"]) && !isset($_REQUEST["name"]) && !isset($_REQUEST["news_name"]) && !isset($_REQUEST["seourl"]) && !isset($_REQUEST["findpost"]) && !isset($_REQUEST["subaction"])) { $tpl->set ( '{newhome_final}', $source);} else { $tpl->set ( '{newhome_final}', "");} $tpl->set ( '{referer}', $referer_block ); $tpl->set ( '{calendar}', $tpl->result['calendar'] ); $tpl->set ( '{top_news}', $top_news ); $tpl->set ( '{last_news}', $last_news ); $tpl->set ( '{rand_news}', $rand_news ); $tpl->set ( '{archives}', $tpl->result['archive'] ); $tpl->set ( '{tags}', $tpl->result['tags_cloud'] ); $tpl->set ( '{vote}', $tpl->result['vote'] ); $tpl->set ( '{topnews}', $topnews ); $tpl->set ( '{login}', $tpl->result['login_panel'] ); $tpl->set ( '{info}', $tpl->result['info'] ); $tpl->set ( '{speedbar}', $tpl->result['speedbar'] ); $tpl->set ( '{catlist}', $catlist ); $tpl->set ( '{moviepopular}', $tpl->result['moviepopular'] );$tpl->set ( '{newhome}', $tpl->result['newhome'] );$tpl->set ( '{newhome_b}', $tpl->result['newhome_b'] );$tpl->set ( '{newhome_c}', $tpl->result['newhome_c'] );$tpl->set ( '{newhome_d}', $tpl->result['newhome_d'] );$tpl->set ( '{newhome_e}', $tpl->result['newhome_e'] ); In my engine/modules folder I have the files: newhome.php newhome_b.php newhome_c.php newhome_d.php newhome_e.php This is the code of engine/modules/newhome_c.php file (Series block): <?php if (!isset($_REQUEST["catalog"]) && !isset($_REQUEST["newsid"]) && !isset($_REQUEST["do"]) && !isset($_REQUEST["page"]) && !isset($_REQUEST["category"]) && !isset($_REQUEST["cat"]) && !isset($_REQUEST["action"]) && !isset($_REQUEST["id"]) && !isset($_REQUEST["name"]) && !isset($_REQUEST["news_name"]) && !isset($_REQUEST["seourl"]) && !isset($_REQUEST["findpost"]) && !isset($_REQUEST["subaction"])) { if( ! defined( 'DATALIFEENGINE' ) ) { die( "Hacking Attempt!" ); } $is_change = false; if ($config['allow_cache'] != "yes") { $config['allow_cache'] = "yes"; $is_change = true;} $tpl->result['newhome_c'] = dle_cache("newhome_c", $config['skin']); $tpl->load_template( 'newhome.tpl' ); if( strpos( $tpl->copy_template, "[xfvalue_" ) !== false ) { $xfound = true; $xfields = xfieldsload();} else $xfound = false; if ($tpl->result['newhome_c'] === false) { $sql = $db->query( "SELECT id, title, date, alt_name, category,xfields,autor FROM " . PREFIX . "_post WHERE category like '%7%' ORDER BY date DESC LIMIT 3" ); while ($row = $db->get_row($sql)) { $catchecks = explode(",",$row["category"]); $catpass = false; foreach ($catchecks as $catcheck) { if ($catcheck == "7") $catpass = true; } if ($catpass) { $sql2 = $db->query( "SELECT alt_name FROM " . PREFIX . "_category WHERE id='$row[category]'" ); $row2 = $db->get_row($sql2); if( $xfound ) { $xfieldsdata = xfieldsdataload( $row['xfields'] ); foreach ( $xfields as $value ) { $preg_safe_name = preg_quote( $value[0], "'" ); if( empty( $xfieldsdata[$value[0]] ) ) { $tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template ); } else { $tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template ); } $tpl->copy_template = str_replace( "[xfvalue_{$preg_safe_name}]", stripslashes( $xfieldsdata[$value[0]] ), $tpl->copy_template ); } } if($config['seo_type']=='1') { $link= "$row[id]".'-'."$row[alt_name]".'.html'; } else { $link="$row2[alt_name]".'/'."$row[id]".'-'."$row[alt_name]".'.html'; } $tpl->set( '{home_title}',stripslashes($row['title'])); $tpl->set( '{home_author}', stripslashes($row['autor'])); $tpl->set( '{home_date}', $row['date']); $tpl->set( '{link}',$link); $tpl->compile('newhome_c'); } } create_cache ("newhome_c", $tpl->result['newhome_c'], $config['skin']); $tpl->clear(); $db->free(); } if ($is_change) $config['allow_cache'] = false; } ?> I think that is everything here :-) Can please someone help me? Hi ive been stuck for a while now and i just cant get my head around it so if you could help i'd be well chuffed. I'm trying to update multple rows in a table depending upon the results of another. I have a form that enables me to update a table called fleet. Another table called ships is realted to the fleet table as each ship is in a fleet: fleet ----- Fleetname* Location Detected ships ------ ShipID* Fleetname * Shipname The particular fleet i am editing is parsed as a url parameter. I made a query to search for all the ships that are in the fleet i am editing: Code: [Select] $colname_ShipsInfleet = "-1"; if (isset($_GET['recordID'])) { $colname_ShipsInfleet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_ShipsInfleet = sprintf("SELECT * FROM ships WHERE FleetName = %s", GetSQLValueString($colname_ShipsInfleet, "text")); $ShipsInfleet = mysql_query($query_ShipsInfleet, $swb) or die(mysql_error()); $row_ShipsInfleet = mysql_fetch_assoc($ShipsInfleet); $totalRows_ShipsInfleet = mysql_num_rows($ShipsInfleet); It searched the ships WHERE the FleetName (which is the primary key of the fleet table) is parsed as a url parameter. The appropriate ship records that are generated i want to use so a field can be updated. For example im updating a fleet record and and setting the location (Planet Name) to a different value. I want the Ship records that are of that particular fleet to update a field (PlanetName) in ship table when the fleet table is updated. Code: [Select] if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE ships WHERE ShipID = $row_ShipsInfleet['ShipID'] SET PlanetName=%s", GetSQLValueString($_POST['select'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); $updateSQL = sprintf("UPDATE fleet SET PlanetName=%s, Detected=%s, Faction=%s WHERE FleetName=%s", GetSQLValueString($_POST['select'], "text"), GetSQLValueString(isset($_POST['checkbox']) ? "true" : "", "defined","1","0"), GetSQLValueString($_POST['hiddenField2'], "int"), GetSQLValueString($_POST['hiddenField'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); I'm really not sure how to proceed here so please if you can help me out that would be ace. Thank You Iam trying to access amazon API and iam receiving XML perfectly but now I dont know how to traverse all records as in the below example Iam having 3 records but can't travers the xml using foreach Loop Please help me out and tell me how to use foreach loop ?? Its urgent $search="9781439181799,9780393334296,9781605298627"; $result = $obj->getItemByUpc($search, "Books"); foreach($result->children() as $key ) { $data = $key->Items->Request->ItemLookupRequest->ItemId."<br/ >"; echo $data; } Moderator Edit: added [php] tags This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=325939.0 Hello, I've been trying this for hours now, looking at different examples and trying to change them to work for me, but with no luck... This is what I am trying to do: I have a simple form with: - 1 input field, where I can enter a number - 1 Submit Button When I enter a number into the field and click submit, I want that number to be send to the php file that is in the ajax call, then the script will take that number and run a bunch of queries and then return a new number. I want that new number to be used to call the php script via ajax again, until no number is returned, or something else is returned like the word "done" or something like that, at which point is simply makes an alert or populated a div with a message... The point is, that depending on the number entered it could take up to an hour to complete ALL the queries, so I want the script that is called to only run a fixed amount of queries at a time and then return the number it is currently at (+1), so that it can continue with the next number when it is called again. I would like to use jquery, but could also be any other way, as long as I get this to work. I already have the php script completed that needs to be called by the ajax, it returns a single number when being called. Thank you, vb |