PHP - Php Table Loop Issue
Hey guys,
I am using php loop to echo out all off the data in my database category within a html table. However I would like to reduce each table row to only 5 results then start a new row so that the table fits within the webpage. Any suggestions? Any help is much appreciated. Thanks. Jason Here is what i am using, but does not fit within the page. Code: [Select] <table cellspacing="10"> <tr> <?php $query = mysql_query('SELECT photo_id, photo_name FROM gallery_photos WHERE photo_category = "Books" AND photo_approved = 1 ORDER BY rand()'); while ($row = mysql_fetch_array($query)) { echo "<td><a href='http://www.mysite.com/view.php?pid=".$row['photo_id']."'><img src='photos/".$row['photo_id'].".jpg' width='115' height='115' /><center><h3><b>".$row['photo_name']."</b></h3></center></a></td>"; } ?> </tr> </table> Similar TutorialsHi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. The first run of my for loop does not execute, but all after that works. I know I need to define my $strings before the for loop because they do not take effect until it has ran once and that is why it does not show the first run. But I don't completely understand how to solve the issue, and have tried everything to my knowledge. The code below imports a steam group page xml and gets the unique ids for each of the groups members, then retrieves information about members. <?php $groupxml = simplexml_load_file('http://steamcommunity.com/groups/MDK-Society/memberslistxml/?xml=1'); $members = $groupxml->memberCount; $array = $groupxml->members->steamID64; for($arraycount="0"; $arraycount<$members; $arraycount=$arraycount+1){ $xml = simplexml_load_file("http://steamcommunity.com/profiles/$array[$arraycount]/?xml=1"); echo "<a href=\"#\" title=\"<img src=$xml->avatarMedium align=right /> $xml->steamID<br />$xml->stateMessage<br /><br />Location: $xml->location<br />$xml->summary\"><img src=\"$xml->avatarMedium\" /></a>"; echo "<br>"; if ("$xml->onlineState" == "online") { echo "<img src=\"images/stateonlinemaster.png\" />"; } elseif ("$xml->onlineState" == "offline") { echo "<img src=\"images/stateofflinemaster.png\" />"; } else { echo "<img src=\"images/stateingamemaster.png\" />"; } echo "<br>"; echo "<br>"; } ?> Could you explain to me fully where I went wrong in the for loop. Thanks I'm starting to get peeved with PHP today, after many hours of trying to sort an issue - I'm sure you all know what I mean. Once again, the issue lies with foreach loops which I have never been able to fully understand, especially when dealing with multiple arrays. The code is for a CMS, where a restaurant owner can update his menu's and choose whether to show them on the website using a tick box. Here's a screenshot.. Essentially, the issue I am having is should I click say, the bottom tickbox and click Update it will for some reason, tick the second in the database.... In reverse, if all are ticked, and I untick the bottom, it will untick the box before it.... it is sooo frustrating.. From what I can see, it is likely to be where the array, where ticked boxes have a value, and non-ticked ones don't... but I tried to sort this in my foreach loop setting an empty value to off.... Here is the HTML code: Code: [Select] <form action="./includes/scripts/menus/update.php" enctype="multipart/form-data" method="post"> <button type="submit" onclick="return confirm('Updating Menu Changes...\n\nUpdating PDF files may time some time.. \n\nDo not navigate away from this page until you recieve a success or failure confirmation.\n\nClick Cancel to make changes.'); { return alert('noob'); }">Update Menu Changes</button> <button type="button" onClick="document.location.href='./includes/scripts/menus/new_row.php'">Add New Menu Item...</button> <br /><br /> <table border="0" width="962" cellpadding="0" cellspacing="0"> <tr style="padding-bottom: 3px;"> <th style="text-align: center;" width="195.4">Active</th> <th style="text-align: center;" width="195.4">Menu</th> <th style="text-align: center;" width="195.4">Current Menu</th> <th style="text-align: center;" width="195.4">Change Menu (PDF format only)</th> <th style="text-align: text-align: center;" width="195.4">Tasks</th> </tr> <? $query = "SELECT * FROM menus ORDER by id ASC"; $query = mysql_query($query) or die(mysql_error()); //Count rows $num_rows = mysql_num_rows($query); //If no rows exist if($num_rows=="0") { ?> <tr style="padding-bottom: 3px;"> <td colspan="4" style="text-align: center;">There are currently no menus listed in the Pen Mill Hotel database.</td> </tr> <? } //If new rows exist elseif($num_rows!=="0") { $i = "0"; while($row=mysql_fetch_array($query)) { //Database Variables $name = $row["menu"]; $id = $row["id"]; $location = $row["location"]; //Establish if a menu is present in database for current entry if(empty($location)) { $current = "<a style=\"cursor: pointer;\" onclick=\"alert('No menu found!');\" title=\"View Listed Menu\">View Current Menu</a>"; } elseif(!empty($location)) { $current = "../includes/menus/" . $row["location"]; $current = "<a href=\"$current\" title=\"View Listed Menu\" />View Current Menu</a>"; } //Establish whether to check tickbox or not. $active = $row["active"]; if($active=="on") { $active = " checked=\"checked\" "; } elseif($active!=="on") { $active = " "; } ?> <tr style="padding-bottom: 3px;" id="<? echo "$id"; ?>"> <td style="text-align: center;"> <input type="checkbox"<? echo "$active"; ?>name="active[<? echo "$i"; ?>]" /> </td> <td style="text-align: center;"> <input type="text" style="padding: 0px;" name="name[]" value="<? echo "$name"; ?>" /> </td> <td style="text-align: center;"> <? echo $current; ?> </td> <!-- Tell PHP, max file size is equal to 5MB (in bytes) --> <input type="hidden" name="MAX_FILE_SIZE" value="5242880" /> <td style="text-align: center;"><input type="file" name="menu_file[]" /></td> <td style="text-align: center;"> <a href="./includes/scripts/menus/delete.php?id=<? echo "$id"; ?>" onclick="return confirm('Are you sure you wish to delete this menu?\n ');"> Delete </a> </td> </tr> <input type="hidden" name="id[]" value="<? echo $id; ?>" /> <? $i++; ?> <? } } ?> </table> <br /> <button type="submit" onclick="return confirm('Updating Menu Changes...\n\nUpdating PDF files may time some time.. \n\nDo not navigate away from this page until you recieve a success or failure confirmation.\n\nClick Cancel to make changes.');">Update Menu Changes</button> <button type="button" onClick="document.location.href='./includes/scripts/menus/new_row.php'">Add New Menu Item...</button> </form> And here is the PHP, baring in mind it will also deal with a file upload, but that isn't the issue at the moment... Code: [Select] <? /* This script is for use on the Manage Menu's pages and updates all menu items. */ /*==================================*/ /* DATE BASE CONFIGURATION */ /*==================================*/ include_once "../../config/config.php"; /*==================================*/ /* SET VARIABLES */ /*==================================*/ $id = $_POST["id"]; $active = $_POST["active"]; $name = $_POST["name"]; $menu_file = $_FILES['menu_file']; $i = "0"; /*==================================*/ /* Loop Each Menu & Update */ /*==================================*/ foreach($id as $key) { //Set Sub Variables if(empty($active["$i"])) { $active["$i"] = "off"; } $active_post = $active["$i"]; $name_loop = $name["$i"]; //Set File Variables $file_name = $menu_file["name"]["$i"]; //name of file on users machine $file_type = $menu_file["type"]["$i"]; //type of file being uploaded $file_size = $menu_file["size"]["$i"]; //size of the uploaded file in bytes $file_error = $menu_file["error"]["$i"]; //returned PHP error codes for upload $file_temp = $menu_file["tmp_name"]["$i"]; //temporary name on server //Handle Uploaded File (if uploaded) if(!empty($file_name)) { //FILE ERROR CHECKS //If file type is not PDF. if($file_type!=="application/pdf") { $pass = "0"; header("Location: ../../../index.php?page=Menus&error=Incorrect_File_Type"); } //If file type is greater than 5MB. if($file_size>"5242880") { $pass = "0"; header("Location: ../../../index.php?page=Menus&error=Incorrect_File_Size"); } //If above error checks pass if($pass!="0") { //Get todays date for file rename $today = date("d-m-Y"); $uploaddir = "/home/penmillh/en/includes/menus/"; $upload_name = str_replace(" ", "", $name_loop) . $today . ".pdf"; $uploadfile = $uploaddir . $upload_name; //Move file only if PHP upload status is correct if($file_error!="UPLOAD_ERR_OK") { header("Location: ../../../index.php?page=Menus&error=File_Upload_Error"); } //If PHP status is okay, upload file and update table. if($file_error=="UPLOAD_ERR_OK") { //Upload move_uploaded_file($file_tmp, $uploadfile); //Update Database $query = "UPDATE menus SET active='$active', menu='$name_loop', location='$upload_name' WHERE id='$value'"; $query = mysql_query($query) or die(mysql_error()); header("Location: ../../../index.php?page=Menus&error=File_Upload_Success"); } } } //If no uploaded file, update database records if(empty($file_name)) { //Update Database $query = "UPDATE menus SET active='$active_post' WHERE id='$key'"; $query = mysql_query($query) or die(mysql_error()); // header("Location: ../../../index.php?page=Menus&error=Menu_Change_Success"); } $i++; } ?> Now, I have probably made this INCREDIBLY complicated, but that's all I could remember from my previous experience with foreach loops.... Any ideas? Im trying to search through the read column and see if any of the rows are read I echo $mail and it shows all the rows for the user. So im grabing the ones I want but now i dont know how to search through what I selected. Or is there a simplier way of having SQL do what im trying to do? Code: [Select] <?php $query = "SELECT `read` FROM pm WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; $results = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($results)) { $mail = $row['read']; } // checks if user has unread mail or not if ($mail == "unread") { echo '<td><b><a href="inbox.php?inbox=1">Messages</a></b></td><td id="diamond">♦</td>'; } else { echo '<td><a href="inbox.php?inbox=1">Messages</a></td>'; } ?> Hello, I have a page where the user uploads a CSV file and I want to read that CSV and update database fields accordingly. It seems I have all the code correct but only the first row of the CSV is being imported. If I echo my variables within the loop, the only output is the first row of the CSV - no subsequent rows. I feel like I'm close but not sure what the issue is? Thanks a million for any help!! Jason //START FILE OPERATION $handle = fopen('uploads/testfile.csv', "r"); //LOOP CONTENTS OF CSV FILE while (($data = fgetcsv($handle, 1000, ",")) !== false) { $importID = $data[0]; $companyName = $data[1]; $primaryPhone = $data[2]; $primaryEmail = $data[3]; $billingFirstName = $data[4]; $billingLastName = $data[5]; $query = 'SELECT importID FROM import'; if (!$result = mysql_query($query)) { continue; } if ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { //UPDATE IF ENTRY EXISTS $query = "UPDATE import SET companyName='$companyName', primaryPhone='$primaryPhone', primaryEmail='$primaryEmail', billingFirstName='$billingFirstName' WHERE importID=$importID"; mysql_query($query); if (mysql_affected_rows() <= 0) { //NO RECORDS UPDATED } } else { //ENTRY DOESN'T EXIST } mysql_free_result($result); } //CLOSE FILE OPERATION fclose($handle); Hi all. How do I loop the below script? $query_basket = mysql_query("SELECT * FROM `store_basket` WHERE sessionid='".$sessionid."'"); $rows = mysql_num_rows($query_basket); $r = mysql_fetch_array($query_basket); $allitems = $rows; while($result_basket = mysql_fetch_array($query_basket)) { $price_without_tax = $result_basket['price']; $tax = 17.5; $price_with_tax = $result_basket['price'] + $tax; $price_times_qty = $result_basket['price'] * $result_basket['qty']; $basket_item = $result_basket['item']; $basket_qty = $result_basket['qty']; $basket_initial1 = $result_basket['initial1']; $basket_initial2 = $result_basket['initial2']; $basket_initial3 = $result_basket['initial3']; } if($allitems == 1) { $basket .= $allitems.":".$basket_item." ".strtoupper($basket_initial1)."-".strtoupper($basket_initial2)."-".strtoupper($basket_initial3).":".$basket_qty.":".$price_without_tax.":".$tax.":".$price_with_tax.":".$price_times_qty; } else { $allitems = $rows; $basket .= ":".$basket_item." ".strtoupper($basket_initial1)."-".strtoupper($basket_initial2)."-".strtoupper($basket_initial3).":".$basket_qty.":".$price_without_tax.":".$tax.":".$price_with_tax.":".$price_times_qty; } Basically if there is more than one row I need to loop the $basket string so that it shows the values for each item. Thanks Pete I am trying to recursively pull records from a database to write to a csv. There are three test rows of data in my table (and no not including the table headers). The only issue is i can’t seem to get my for loop to display all the records – it only displays the last 2 rows so i’m very confused. Anyone suggest why this isn’t working? Code: [Select] $num_rows = mysql_num_rows($export); for ($i=0; $i <= $num_rows; $i++ ) { $row = mysql_fetch_row($export); echo $row[1] . $row[2] . $row[3] . $row[4] . $row[5] . $row[6] ."<br/>"; echo $i; } Incidentally the query is just a fetch all from datasbase. Anyone see where i'm going wrong? Thanks, drongo Hey there folks, Im trying to get a foreach loop working correctly from a json source epg heres my code: https://pastebin.com/FjHj1EF6 Here is the current output, which.. while correct is only the first instance of these values i wanted using the foreach loop, i would love any tips on why my approach failed and to be pointed in the right direction. While it has to be included: $url = "https://mywebsite.fake/mlb.php?id={$arr['games'][0]["gamePk"]}"; this value isn't related to the assistance im asking for. that will work for my purposes later. but for now i just need to understand the issue with the foreach loop. Thanks in advance for your thoughtful response. mosb3rgler 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 Let me explain my problem. I have an array with dates and numbers in format ($cronograma) Ex: Array ( [2020-09-21] => Array ( [0] => 2020-09-21 [1] => 2 [2] => 2 [3] => 2 ) [2020-09-28] => Array ( [0] => 2020-09-28 [1] => 2 [2] => 2 [3] => 4 ) Then i have another array with 2 ids (in this case 58,60) ($id) Finally i have a third array with numbers only (in this case 34,34) $tot So what i want is cross information beween them, for example for id 58 I must get dates (first element and last element when $tot = 34) for id 60 I must get dates (first element after $tot =34 and last element of array) Whath i have so far is this foreach ($id as $idPlan) { foreach ($cronograma as $c) { $t1 = 0; foreach ($tot as $d) { $t1 += (int)$d['tempos']; if ($c[3] == $t1) { $newAr[] =$idPlan; $newAr[] = $c[0]; } } } } My response array(8) { [0]=> string(2) "58" [1]=> string(10) "2021-02-01" [2]=> string(2) "58" [3]=> string(10) "2021-06-14" [4]=> string(2) "60" [5]=> string(10) "2021-02-01" [6]=> string(2) "60" [7]=> string(10) "2021-06-14" } null So it's clear that i have all repeated I should have a line like: 58 - 2020-09-21 -2021-02-01 Any help? Using a for loop counting from 0 to 9, I need to make this into a table. Making sure the table is 100% of the page. Any sort of help is appreciated. Thank you 0 1 2 3 4 5 6 7 8 9 Hi, When I use the below table in a while loop, it will repeat down the page. I want it to repeat in rows of 3, how can I do this? Code: [Select] while () { echo ' <table width="50%" cellpadding="2" cellspacing="1" bgcolor="'.$border.'"> <tr > <td colspan="5" height="20" align="center" class="title" bgcolor="'.$bghead.'"><b>'.$pt['platform'].'</b></td> </tr> </table>'; } Thanks! There is only one row out of 7 rows in the database displaying in the table. I have debug the code bug it keeps displaying only one results? I know it should be some problem with the table and not with the while loop or the other way around. help! Code: [Select] <?php $dynamicList = ""; $sql= mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); if ($productCount>0 ) { while($row = mysql_fetch_array($sql)) { $id= $row["id"]; $product_name= $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList = '<table width="100%" border="0" cellpadding="6" cellspacing="0"> <tr> <td width="17%" valign"top"><a href="product.php?id='.$id.'"><img style="boder:#666 1px solid", src="inventory_images/'.$id.'.jpg" alt="'.$product_name.'" width="90%" height="102" border="0" /></a></td> <td width="65%" valign="top">'.$product_name.'<br />$'. $price . ' <br /> <a href="product.php?id='.$id.'">View Product Details</a></td></tr></table>'; } } else { $dynamicList = "We have no products listed in your store yet"; } ?> <!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>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="131" height="92" valign="top">some crap</td> <td width="112" valign="top"><p>Newest items Added to the Store</p> <p><?php echo $dynamicList; ?><br /></p> </td> <td width="84" valign="top">More Crap</td> </tr> </table> </div> </body> </html> I have 2 question, which are related to each other. They are about my current school project. Which I have been really stupid for, I took it too slow and thought I had enough time. But no, I had to do almost my whole project in the last 3 weeks and sunday is the deadline. I have a couple pages to make left, which one of them is the hardest one and I have the 2 questions about it. Question 1. I have to make a invoice with 4 different prices, divided over 3 tables in my mysql. Let me sum up the tables. Products Productsid - productprice Productrule Productruleid - amount - productid - maintainanceid Maintainance Maintainanceid - price I need to show the price The price of each product The amount * productprice The amount * productprice + price All in a table, it mustn't be edited, so it not in a form. I know I have to use a SQL select sum for it, but I have never used it, and my querys always fail in the first place I used a for and while loop to choose the amount of and the name of products for the mechanic page. There was a max of 5 products to select, just to keep it easier. If I would only pick 2, it wouldn send something empty to the database and it wasn't required. My teacher helped me with that and it works. So then we come to question 2, can I use that in a table, instead of a drop down menu, which I used at the mechanic page. This is the PHP code: Code: [Select] for($i=1;$i<=5;$i++) { if(($_POST['aantal'.$i] != "") AND ($_POST['product'.$i] != "")) { $query3 = mysql_query ("INSERT INTO onderdeelregel SET aantal='".$_POST['aantal'.$i]."', onderdelenid='".$_POST['product'.$i]."', werkzaamhedenid='".$werkzaamhedenid."'"); } } And the HTML: Code: [Select] <table border="0"> <tr> <th>Aantal</th> <th>Product</th> <tr> <!-- START BLOCK : PRODUCT_REGEL --> <tr> <td> <input class="wijzigInput" name="aantal{NUMMER}" id="aantal" type="text" maxlength="2" size="2" /></td> <td> <select name="product{NUMMER}"> <option selected="selected" class="wijzigOption" value=""></option> <!-- START BLOCK : PRODUCT_REGEL_OPTION --> <option class="wijzigOption" value="{PRODUCT_REGEL_WAARDE}">{PRODUCT_REGEL_NAAM}</option> <!-- END BLOCK : PRODUCT_REGEL_OPTION --> </select> </td> </tr> <!-- END BLOCK : PRODUCT_REGEL --> </table> Oh I didn't used a while loop there, but I know I have to use it in the customer page. I know this isn't going to work on my own, and I haven't got much time left. I would really appreciate it if anyone could give me some code, or atleast a start of the sql select sum and the for and while loop in a table. I know I have add other stuff to the invoice, but that isn't hard, so with this I should be able to do it and finish my project in time. I usually don't like that, I want to learn it myself, but time is very little right now Oh and sorry for the Dutch in my code. Please help me, I don't want to stress out and fail it. School is very important to me and I hate myself for taking it so slow. Thanks a lot Chris I am trying to place a unique number into a mysql table. Currently, my code generates a random number, then is supposed to scan through the table for that number. If the code finds that number already in the table, it generates a new random number and repeats the process. I have commented my code for the purpose of this help forum: Code: [Select] $result = mysqli_query($link,"SELECT * FROM testTable"); do { $end = true; //prepares end of loop $idNum = rand(1,10); //rand(1,999999); <-- for testing purposes I have reduced the number generated $idNumTx = (string)$idNum; //loop through the rows while ($row = mysqli_fetch_assoc($result)) { if ($row['idNum'] = $idNum) //check if the random number equal to this row { $end = false; //prep end of loop repeat echo $idNumTx; //display rand number that failed for testing purposes echo " NO! "; //display error for testing purposes } } } while(!$end); I know I must be doing something wrong, as when I run this, it runs the if statement within the while loop always executes, and I get an output like: Code: [Select] 1 NO! 1 NO! 1 NO! 1 NO! 1 NO! 1 NO! 5 Win Win is when it places the value before it, in this case 5, into the table. However, the value of 5 might already be in the table and it doesn't seem to matter. I execute the code multiple times, and it seems to increase the number of "# NO!" almost (but not every) time. However, each time ALL of the "# NO!" are the same #, and the "# Win" just seems to be random (as it should be, but not unique). Checking the table after shows me random numbers between 1 and 10 (as it should) in the correct field, but the are not unique. (Ex/ Both row 1 and 5 could have the same value, say 6) I'm hopefully doing something simple wrong, so someone please point it out to me Hey guys..i have an issue i can't seem to fix...
i have a table with codes and userid to associate the code to a user i need to make it that a user can give codes to another user. i have a form . from user to other user with amount of codes
so i have tried many combos.. $UserID = mysqli_real_escape_string($DBcon, $_POST['OwnerID']); $NewRId = mysqli_real_escape_string($DBcon, $_POST['SubID']); $Cr = mysqli_real_escape_string($DBcon, $_POST['credits']); tried with range $t = array(); $counter = 0; foreach (range(0, $Cr) as $t) { $sql = "UPDATE `Codes` SET `UserID`= '$NewRId' WHERE `UserID` = '$UserID'"; $counter ++; echo $counter; } $result = mysqli_query($DBcon,$sql); if (!$result) { trigger_error("UPDATE query failed: " . mysqli_error(), E_USER_ERROR); } but it takes all the ocdes from user one to user two... tried also: foreach ($Cr as $t) { $sql2 = "UPDATE `Codes` SET `UserID`= '$NewRId' WHERE `UserID` = '$UserID'"; if ($DBcon->query($sql2) === TRUE) { echo "<meta http-equiv=Refresh content=1;url=SwapC.php?success=1 >"; } else { echo "Error updating record: <br>" . $DBcon->error; } } but does not work...
this is my sql code Code: [Select] <?php $query = "SELECT Player, SUM(GLI) AS 'gli', SUM(Goals) AS 'goals', SUM(Saves) AS 'saves', SUM(SOG) AS 'sog', SUM(Assists) AS'assists', SUM(CK) AS 'ck', SUM(YC) AS 'yc', SUM(RC) AS 'rc' FROM pinkpanther_stats GROUP BY Player; "; ?> their are 11 separate players and i want to set variables $adam_glie and $tyler_glie equal to the glie column for that player(the player being the first part of the variable) and i dont have any idea how to go about doing this Good day: Im trying to get a numer from a table and use it to know how many pages are in the article so the script knows how many hyperlinks for the pages to generate (ex. links for pages 1 to 5). This is the script so far: Code: [Select] <?php $aid = $_GET['aid']; $sd = $_GET['sd']; $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT pages FROM articles_description WHERE articleid=$sd"; $result=mysql_query($query); $num=$result; mysql_close(); ?> <table width ="600" border="0" cellspacing="2" cellpadding="2" align="center"> <th><font face="Arial, Helvetica, sans-serif">pages</font></th> <?php $i=1; while ($i <= $num) { ?> <td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo "<a href=\"$f3?aid=$aid&sd=$i\" target=\"_self\">$i</a>"; ?></font></td> </td> <?php $i++; } ?> Any help will be appreciated. The following generic code prints out a given table in my database, by first getting the fieldnames and putting them as the title of each column, and then getting the values. How do I change it so that if the name of the field is "password", the value will echo "----" instead of the password? $sql = "SELECT * FROM $tablename"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $row = 1; ?> <table width="90%" border="1"><?php //the MYSQL_ASSOC gets field names instead of numbers while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row == 1) { ?><tr><?php foreach ($line as $col_key => $col_value) { ?><th><?php echo $col_key;?></th><?php } ?></tr><?php } ?><tr><?php foreach ($line as $col_value) { ?><td><?php echo $col_value;?></td><?php } ?></tr><?php $row++; Hello forum. I'm new here, but I've been reading and finding useful things for a while now. I'm still new to PHP and I need a little help. I'm doing a school project and I have some things I want to do, but do not know how to write it down in PHP. I think I'll ask a lot of questions this week, and I hope I will get some help.. For start I want to ask this: I've been using Code: [Select] mysql_fetch_array() for doing loops and populating check-boxes. And everything's working fine.. but what I want is to control the actual loop by clicking buttons. Let's say first time a while-do is run, my check-boxes get populated from the database and every other loop the next data from the table is added.. pretty straightforward. I want to be able to populate once, then click "next" and the new data to be added and so on.. Code: [Select] <?php $tema = mysql_query("SELECT * from questions")or die(mysql_error()); function answer1($string) { $string1 = explode("/", $string); echo $string1[0]; } function answer2($string) { $string1 = explode("/", $string); echo $string1[1]; } while ($row=mysql_fetch_array($tema)) { echo mysql_fetch_array($tema); $tip=$row["tip"]; if ($tip==2) { $id=$row['prasanje_id']; $question=$row['question']; $answer=$row['answer']; ?> <label> <?php echo $question?></label><br> <input type="checkbox" name="CheckboxGroup1" value="checkbox" id="CheckboxGroup1_0" /> <?php answer1($tekst) ?></label> <label> <input type="checkbox" name="CheckboxGroup1" value="checkbox" id="CheckboxGroup1_1" /> <?php answer2($tekst) ?></label> <?php } } ?>I want an alternative to the while-do loop.. Is it possible to do this? Thanks!! |