PHP - Store The Id Number Inside "one" Array Inside For Loop?
The Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? Similar TutorialsThe Script:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type="text" name="hashtags" /> <input type="submit" name="submit" /> </form> <?php include("connect.php"); ?> <?php if(isset($_POST['submit'])){ $hashtags = explode(", ", $_POST['hashtags']); for($i= 0; $i < count($hashtags); $i++){ $tqs = "SELECT `id` FROM `hashtags_two` WHERE `hashtags` = '" . $hashtags[$i] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } $fetch_array = array(); while($row = mysqli_fetch_array($tqr)){ $fetch_array[] = $row['id']; } }Hey, sorry for these fundamental array questions lately, I am not going to ask much more when it comes to this. The hashtags come from the submit form (separated by commas) and get stored inside an array with the "explode()" function. The script should select the ID numbers of the hashtags from the table. With the script above only the last row gets inserted into $fetch_array inside the while loop. When the $fetch_array variable is printed on screen then only one ID number can be seen inside the array: Array ( [0] => 24 )How can I have the other ID numbers too? Code: [Select] //this varible contains the array of existing users $existing_users=array('roshan','mike','jason'); //value got from the get metho $user_name=$_POST['user_name']; //checking weather user exists or not in $existing_users array if (in_array($user_name, $existing_users)) { //user name is not available echo "no"; } else { //username available i.e. user name doesn't exists in array echo "yes"; } the array near the top has a list of users, I would like to loop through my users in my database I know how to write a loop but not into here Code: [Select] $existing_users=array('roshan','mike','jason'); Hello all, What I'm trying to do is insert dynamic data supplied by the user into an array, but for some reason, the loop only builds arrays inside of arrays (or so it seems) and doesn't create an array with unique indexes and associated data. I was hoping someone could point me in the right path? I've searched numerous forums, threads and google but cannot find an answer. Here is the code snippet I'm working on. What it's supposed to do is collect a user's input, which is a Quantity amount and a high number, and based on that amount, create an array of random integers. This is my latest attempt. Now, maybe I'm just losing it, but when I place print_r($output) inside the loop, I see how it's being created but no unique indexes, just nested arrays. When I place it outside of the loop, I only receive one array with one index and value even though a high quantity was sent to the script. Code: [Select] $i = 1; while ($i <= $Quantity){ $output = array(rand($RandLow, $RandHigh)); $i++; } print_r($output); Here is another attempt, which again proved to be unsuccessful, at least to my tire brain. Code: [Select] $i = 1; while ($i <= $Quantity){ $output = rand($RandLow, $RandHigh); $total = array($output); $i++; } print_r($total); I've tried the for() loop as well but I just can't seem to make heads or tails of this and I'm sure it's going to be something simple that I'm missing. Thanks in advance for any help and insight if you know a better way to do this. how can you increase the page number in the following line until $status returns an empty result? curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/xml", "Authorization: xxxxxxxxxxxxx:xxxxxxxxxxxxxxxx", "Page: 2")); After it goes through the while loop its supposed to take the ID of the first one in the loop and find out its awardType and then with the awardType variable go through the the if statement. After it displays it the code that fits the awardType variable then it gets the second item in the while loop and then with the ID of the second item takes it back to get the awardType and then goes back through the if statement again. I'm not sure what I'm doing wrong. As of right now all its doing is displaying its awardName and a blank dropdown. Code: [Select] <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php');l $userID = $_SESSION['userID']; $statusQuery = " SELECT * FROM statuses"; $statusResult = mysqli_query ( $dbc, $statusQuery ); // Run The Query $awardQuery = " SELECT awards.ID, awards.awardName, awards.awardType FROM awards"; $awardResult = mysqli_query ( $dbc, $awardQuery ); // Run The Query $row = mysqli_fetch_array ( $awardResult, MYSQL_ASSOC ); $awardType = $row[ 'awardType' ]; $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query $matchQuery = " SELECT eventSegments.ID, eventSegments.segmentTitle FROM eventSegments INNER JOIN events ON eventSegments.eventID = events.ID WHERE DATE_FORMAT(events.bookingDate,'%Y') = DATE_FORMAT(curdate(),'%Y')"; $matchResult = mysqli_query ( $dbc, $matchQuery ); // Run The Query ?> Code: [Select] <fieldset> <legend>Nominees</legend> <?php mysqli_data_seek( $awardResult, 0 ); while ( $row = mysqli_fetch_array ( $awardResult, MYSQL_ASSOC ) ) { ?> <?php if ($awardType == 'Singular') { ?> <div class="field required"> <label for="charactersDrop"><?php echo $row['awardName']; ?></label> <select class="dropdown" name="charactersDrop" id="charactersDrop" title="Characters Drop"> <option value="">- Select -</option> <?php while ( $row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r"; } ?> </select> <input type="button" value="Add Character" class="" onclick="HandlerCharacters()"/> <ul id="characterList"> </ul> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <? } else { ?> <div class="field required"> <label for="events"><?php echo $row['awardName']; ?></label> <select class="dropdown" name="events" id="events" title="Events for <?php echo date("Y") ?>"> <option value="">- Select -</option> <?php while ( $row = mysqli_fetch_array ( $matchResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['segmentTitle']."</option>\r"; } ?> </select> <input type="button" value="Add Match" class="" onclick="AddMatch()"/> <ul id="matchList"> </ul> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <?php } ?> <?php } ?> Currently whether data from the queries are found or not, its surrounded inside the div tags... i want to somehow echo the div tags inside the while loop, but only echo once. the confusing part for me is that the queries are connecting to 2 different tables for data.. and both need to be found for the div to be echo. if($item['quantity'] >= 1){ if($item2['type'] == 'weapon'){ code below.... Code: [Select] <div class="g_content"><h3 style="text-align: left"> Weapons</h3><div class="g_text"> <table align='center' cellspacing='10'> <?php $current_col = 1; $max_col = 4; $query = $db->execute("select * from items where `player_id`=?", array($player->id)); while($item = $query->fetchrow()) { $query2 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['item_id'])); $item2 = $query2->fetchrow(); //DISPLAY IF QUANTITY IS 1 OR MORE. if($item['quantity'] >= 1){ if($item2['type'] == 'weapon'){ //Open new row if first column if($current_col==1) { echo "<tr>\n"; } //Display current record echo "<td width='25%'>"; echo "<center><img src=\"{$item2['img']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item2['id']}\">{$item2['name']}</a> [x".$english_format_number = number_format($item['quantity'])."]</center>"; echo "<center>$".$english_format_number = number_format($item2['value'])."</center>"; echo "<center>[<a href='../item.php?sell=".$item['id']."'>Sell</a>] [<a href='../item.php?market=".$item['id']."'>Market</a>] <br>[<a href='../item.php?send=".$item['id']."'>Send</a>] [<a href='../item.php?equip=".$item['id']."'>Equip</a>]</center><br>"; echo "</td>\n"; //Close row if last column if($current_col==$max_col) { echo "<tr>\n"; $current_col = 0; //<---Changed } $current_col++; } } } //Close last row if needed if ($current_col!=1) { for(; $current_col<=$max_col; $current_col++) { echo "<td> </td>\n"; } } ?> </table> </div></div> i have a variable called $cake it needs to have this loop inside it so I can call it out Code: [Select] while( $r = $DB->fetch_row() ){ if ( $r['last_activity'] > (time() - 900) ) $r['status'] = "<span style=float:right;><span class=desc4><b>Online</b></span></span>"; else $r['status'] = "<span style=float:right;><span class=desc4>Offline</span></span>"; $column++; if ($ibforums->member['settings']['2'] or (!$ibforums->member['id'])){ $color = "{$r['color']}"; $colors = explode(",", $color); if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ { $r['color'] = ($r['color']) ? "style=\"padding:1px 1px 1px 2px;color:#{$colors[0]};filter:Glow(color=#{$colors[1]},strength=3)\"":""; } }else{ $r['color'] = ($r['color']) ? "style=\"color:#{$colors[0]};text-shadow:#{$colors[1]} 2px 1px 1px\"":""; } } $test = explode(";", $info['pdata']); $r['avatar'] = ($r['avatar']) ? "<img src={$r['avatar']} width=64 height=64>" : ""; $r['star'] = ($r['star']) ? "<img class=top3 src=style_images/1/icons/{$r['star']}.png>":""; $r['name'] = "<a href=?i={$r['friendid']}>{$r['name']}{$r['star']}</a>"; $this->to_print .= <<< LOL <dl class="LOL LEFT flm" style="margin-right:5px"><dt2>{$r['name']}</dt2><dd class=padding4>{$r['avatar']}<div class="RIGHT">{$r['status']}</div></dd></dl> LOL; } I tried: Code: [Select] $cake = ' while( $r = $DB->fetch_row() ){ if ( $r['last_activity'] > (time() - 900) ) $r['status'] = "<span style=float:right;><span class=desc4><b>Online</b></span></span>"; else $r['status'] = "<span style=float:right;><span class=desc4>Offline</span></span>"; $column++; if ($ibforums->member['settings']['2'] or (!$ibforums->member['id'])){ $color = "{$r['color']}"; $colors = explode(",", $color); if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ { $r['color'] = ($r['color']) ? "style=\"padding:1px 1px 1px 2px;color:#{$colors[0]};filter:Glow(color=#{$colors[1]},strength=3)\"":""; } }else{ $r['color'] = ($r['color']) ? "style=\"color:#{$colors[0]};text-shadow:#{$colors[1]} 2px 1px 1px\"":""; } } $test = explode(";", $info['pdata']); $r['avatar'] = ($r['avatar']) ? "<img src={$r['avatar']} width=64 height=64>" : ""; $r['star'] = ($r['star']) ? "<img class=top3 src=style_images/1/icons/{$r['star']}.png>":""; $r['name'] = "<a href=?i={$r['friendid']}>{$r['name']}{$r['star']}</a>"; $this->to_print .= <<< LOL <dl class="LOL LEFT flm" style="margin-right:5px"><dt2>{$r['name']}</dt2><dd class=padding4>{$r['avatar']}<div class="RIGHT">{$r['status']}</div></dd></dl> LOL; }'; but not working Hi there, Having an issue here. I have a site where you can join a group. When the user goes to the groups page it will list their groups that they have joined. This is fine. I also want to be able to show how many other members are in that group and am getting stuck. $row group_name works ok but not sure how to start by adding another while loop in for the members. The table consists of group id, group name, member id (L_ID) and member name $result = mysql_query("SELECT * FROM groups2 WHERE L_ID = ". $_SESSION['member_ID'] .";"); while ( $row = mysql_fetch_array($result) ) { echo("<tr> <td><font face='Arial, Helvetica, sans-serif' size='3'><strong>" . $row["group_name"] . "</strong></font></td> </tr><tr> <td><font face='Arial, Helvetica, sans-serif' size='1' color='#0000FF'><strong>Members ("???")</strong></font></td> </tr><tr> <td><hr width=95%><br></td> </tr>"); } im having problems with the count in the if statment. its only counting the last value _posted. im missing something really simple but i can not see it. help please. Code: [Select] <?php $count= $_GET['seatco']; for ($i=1; $i<=$count; $i++) { $ticket = $_POST['tick_com'.$i]; echo "tickets: ".$ticket; echo "<br>"; $adult= "0"; $child= "0"; $concession = "0"; if ($ticket =="adult") { $adult++; } elseif($ticket == "child"){ $child++; } elseif($ticket =="concession"){ $conc++; } else{ echo "no";} } } echo "Adult".$adult; echo "Child".$child; echo "Concession".$conc; ?> I've seen two post now about not deleting within a loop and I think I may need to ask a question about this. I have a photograph db that gives the addresses of the thumbs and photos in files for a product, it also is keyed to the products db. There can be more than one photo per product. If someone selects yes from a radio button and clicks submit the process should delete the record of the product in the product db, delete the photos in the photo images/files(this is the loop) and then delete the product id and row in the photo db Is this a decent way of doing this? if ($_POST['sure'] == 'Yes') { // If Yes delete the item and its pictures in image folders $q = "DELETE FROM product WHERE id = $item LIMIT 1"; // Delete the product record $r = @mysqli_query ($dbc, $q); $q = "SELECT id, thumb, photo FROM photos WHERE id = '$item'"; $r = @mysqli_query ($dbc, $q); if ($r){ while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ unlink('images/members/'.$row['thumb'].''); // Remove-delete photos from folders for each row in photo db unlink('images/members/'.$row['photo'].''); } } $q = "DELETE FROM photos WHERE id_prod = $item"; // Delete the photo record $r = @mysqli_query ($dbc, $q); // When through redirect header("Location: $home/member/index.php?user=$mem_id"); exit(); } Hey Before I start playing around with some code I want to know if it is possible to call a function inside a while loop that will call echo a some stuff then return to the loop it got called by? thanks Hi everyone, greetings from Brazil.
I am an average php coder, much more a designer than an programer, and i am in a looper trouble..
Can anyone try to help me?
Here is my code:
<table border="1"> <tr> <?php //pega cada uma das operadoras do campo operadoras $operadoras = $opers_trazOperadoras ; $logos = explode(",",$operadoras); $x = 0 ; foreach ($logos as $v) { mysql_select_db($database_webroker, $webroker); $query_trazLogoOperadora = "SELECT * FROM tb_operadora WHERE tb_operadora.id_operadora = " . $v ; $trazLogoOperadora = mysql_query($query_trazLogoOperadora, $webroker) or die(mysql_error()); $row_trazLogoOperadora = mysql_fetch_assoc($trazLogoOperadora); $totalRows_trazLogoOperadora = mysql_num_rows($trazLogoOperadora); ?> <td><img src="http://www.we-broker...imagens_upload/<?php echo $row_trazLogoOperadora['logo']; ?>"> <?php do { ?> <?php } while ($x++ < 4); { echo $x ;?> </td></tr><tr> <?php } $x = 0 ; } ?> </table> The URL for this code is: http://valsegs.we-br...radorasPATO.php Tks! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316454.0 Good Evening - I am in the process of trying to call back a list of categories and sub categories using a WHILE LOOP inside of a WHILE LOOP. It works on a different part of the site within the admin panel but not here. Here it only calls one sub category and moves on to the next parent category instead of finishing the loop and pulling all sub categories out... // CATEGORIES $query = "SELECT * FROM cat"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $catid = $row['id']; $catname = $row['name']; $output .= "<li class=\"level0 nav-2 parent\" onmouseover=\"toggleMenu(this,1)\" onmouseout=\"toggleMenu(this,0)\"> <a href=\"product.php?cat=$catid\"> <span>$catname</span> </a>\n"; $querynav = "SELECT * FROM subcat WHERE pid = '$catid'"; $resultnav = mysql_query($querynav); while($array = mysql_fetch_array($resultnav, MYSQL_ASSOC)) { $subcatid = $row['id']; $subcatname = $row['name']; $output .= "<ul class=\"level0\"> <li class=\"level1 nav-2-1 first\"> <a href=\"product.php?cat=$catid&subid=$subcatid\"> <span>$subcatname</span> </a> </li> </ul> </li>"; } } Hi.. I have table which has a data so_month: FromMonth : 5 ToMonth : 7 and I have table working_days: MonthName May Jun Jul MonthNumber 05 06 07 WorkingDays 23 24 23 Now I have function to get the 3 consecutive months from FromMonth to ToMonth , which as you can see from May to Jul Now I have problem in getting the SUM of Working days. here is my code: <?php $sql = "SELECT FromMonth, ToMonth FROM so_month"; $res = mysql_query($sql,$con); $row = mysql_fetch_assoc($res); $FromMonth = $row['FromMonth']; $ToMonth = $row['ToMonth']; function monthNames($from, $to){ $range=array(); for($i=$from; $i<=$to; $i++){ $range[$i]=date('M', mktime(0,0,0,$i)); } return $range; } $month_ = implode("' ', ",monthNames($FromMonth,$ToMonth)); foreach( monthNames($FromMonth, $ToMonth) as $month){ $sql = "SELECT MonthName, SUM(WorkingDays) AS WorkingDays FROM working_days WHERE MonthName IN ('$month') GROUP BY MonthName"; $res = mysql_query($sql, $con); while($row = mysql_fetch_array($res)){ $WorkingDays = $row['WorkingDays']; } echo $WorkingDays; } ?> the output of this code is: 232423 and when I change this line: $WorkingDays = $row['WorkingDays']; to $WorkingDays += $row['WorkingDays']; the output is: 234770 I correct output should be: 70 Any help is highly appreciated. Thank you very much.. greetings! I have here codes that have two checkboxes, if 1 checkbox is checked, the other and textbox is disabled. I think my codes in js is functional, my problem is how to put it inside the mysql_fetch_array, I want to put those checkbox in every data fetch from my db. only the first data is affected ..i really appreciate your help guys! <?php include('connect-db.php');?> <html> <head> <script language = "Javascript" type="text/javascript" > function checkbox_disabled(tocheck,todisable,todisable2) { var x = document.getElementById(tocheck); if(x.checked){ document.getElementById(todisable).disabled=true; document.getElementById(todisable2).disabled=true; document.getElementById(todisable2).checked = false; }else{ document.getElementById(todisable).disabled=false; document.getElementById(todisable2).disabled=false; document.getElementById(todisable2).checked = true; } } </script> </head> <body> <?php echo "<table>"; $query = mysql_query("SELECT * FROM tbl_user") or die (mysql_error()); while ($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td>'.$row['user_Id'].'</td>'; echo '<td>'. $row['user_Fname'].'</td>'; echo '<td>'.$row['user_Lname'].'</td>'; echo "<td><input type='checkbox' id='checkbox1' value ='checked' onclick=checkbox_disabled('checkbox1','textbox1','checkbox2')></td>"; echo '<td><input type="checkbox" id = "checkbox2"><input type="text" id="textbox1" /><td>'; echo '</tr>'; } echo "</table>"; ?> </body> </html> Is there a way to stop loop inside a switch or i must use if instead of switch? Example: <?php for( $i = 0; $i < 10; $i++ ) { switch( $i ) { case 1: break; case 2: // break from loop here break; case 3: break; } } ?> Thanks Hi... I have form which data is inside while loop and per row has a approved button, Now I have no idea that when I click the approve button the JO # from that row will display and save to the database. here is my code and sample form. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Sales Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <form name="loading_kanban" action="" method="post"> <div id="SR_date"> <label>Date :</label> <input type="text" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="kanban_table"> <table> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Requirements </th> <th> Priority</th> <?php $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order"; $res_so = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_so)){ $ETD = $row['ETD']; $PO_No = $row['PO_No']; $SKUCode = $row['SKUCode']; $Description = $row['Description']; $POReq = $row['POReq']; echo "<tr> <td> </td> <td>$ETD</td> <td>$PO_No</td> <td>$SKUCode</td> <td>$Description</td> <td>$POReq</td> <td> </td> <td><input type='button' name='priority' value='Approved' id='priority'></td> </tr>"; } ?> </table> </div> </form> </body> </html> I'm using this line a lot on my site. It would be nice if I didn't have to change it 10 times over when I decide to change something. Can I wrap that into a Function and use it in a While loop? echo '<div><a href="/tag/'. strtolower($nameFirst) . '-' . strtolower($nameLast) .'">'. $nameFirst . ' ' . $nameLast .'</a>, '; I have this above it in the While loop.
$nameFirst = $row['nameFirst'];
My function predictably looks like this... function player_name () { echo '<div><a href="/tag/'. strtolower($nameFirst) . '-' . strtolower($nameLast) .'">'. $nameFirst . ' ' . $nameLast .'</a>, '; }
Hi - I have spent 2 days trying to figure this out. I must be doing something stupid ... I am trying to update the DB with a collection of variables off of a various POST array's. I have indexed the variables so that I can loop through them with a FOR. However I am having all kinds of trouble: 1 - WEIGHT is giving 5 values even though the counter should only go 4 times. 2 - The WEIGHT variable is going into the wrong field in the DB even though I specify in my Query a specific place. 3 - I get undefined offset errors even though I have initialised the variables with their respective offsets. 4 - Adding the conditional statement adds even more offset errors even though they are initialised I am starting to wonder if my entire approach to updating my DB is flawed. As a student of PHP I think I need someone with more experience to look at what I am doing and tell me if something jumps out at them. There is a lot of statements echoing out values - and they all seem to check out. Man Many thanks for your advice Code: [Select] function finishedorder(){ $prodname = $_POST['prodname']; $prodid =$_POST['prodid']; $quantity = $_POST['quantity']; $pricelb = $_POST['pricelb']; $customerid = $_POST['customerid']; $price = $_POST['price']; $orderid = $_POST['orderid']; $weight = $_POST['weight']; echo "Varuable WEight"; print_r($weight); echo"<br/>"; echo "line 196 Weight"; print_r ($_POST['weight']); echo"<br/>"; echo "line 192 PriceLB"; print_r ($_POST['pricelb']); echo "<br/>"; echo "line 193 Price"; print_r ($_POST['price']); echo "<br/>"; echo "line 194 ProdID"; print_r ($_POST['prodid']); echo "<br/>"; echo "line 195 OrderID"; print_r ($_POST['orderid']); echo "<br/><br/>"; $numloops = count($_POST['prodid']); for ($i = 0; $i < $numloops ; $i++) { // !!! Start of the for loop !!! if (!isset($orderid[$i])) $orderid[$i] =''; if (!isset($prodid[$i])) $prodid[$i] =''; if (!isset($weight[$i])) $weight[$i] =''; if (!isset($pricelb[$i])) $pricelb[$i] =''; // This only initialises the Price & Weight variable to avoid an offset error message. if (!isset($weight[$i])) $weight[$i] =''; $ordervalue = $pricelb[$i] * $weight[$i]; echo " L. 216 The number is " . $i . "<br />"; echo "line 221 ProdID".$prodid[$i];echo "<br/>"; echo "line 217 Pricelb".$pricelb[$i];echo "<br/>"; echo 'Weight L. 219 weight[i]'. $weight[$i];echo "<br/>"; echo "line 220 weight".$weight; echo "<br/>"; echo "line 221 Numloops".$numloops; echo "<br/><br/>"; echo ' L. 225 $ordervalue ' .$ordervalue;echo "<br/>"; } //if ($pricelb[$i] == 0 ){ // conditonal statement // $ordervalue = $price[$i]; // } $sql =" UPDATE confirmedorder SET weight='$weight[$i]', ordervalue='$ordervalue', confirmedorder.picking = 'finished', confirmedorder.sale = 'open' WHERE prodID = '$prodid[$i]' AND OrderID = '$orderid[$i]' ; "; $this->db->query($sql); } // !! End For Loop. !! |