PHP - Repeating Checkboxes Problem
Hi Folks,
I am looping through a recordset ($result) containing different languages which I convert to values of html checkboxes, I want to compare the recordset values to array values ($arr_languages_spoken) and check the checkboxes that match. I think I am close, the code I have checks the right boxes but duplicates every value from the recordset so I have 2 of each checkbox, any help would be appreciated, thanks. MY CODE while($row = mysql_fetch_array($result)) { foreach ($arr_languages_spoken as $value) { if ($value == $row['language']) { echo "<input type=checkbox name=languages_spoken_1 value=".$row['language']." CHECKED/>".$row['language']." "; } else if ($value != $row['language']) { echo "<input type=checkbox name=languages_spoken_1 value=".$row['language']." />".$row['language']." "; } } } Similar TutorialsI'm trying to make it so that if the $row data is more than just "" (empty) then echo if not then run the scan on the next number. It just keeps repeating the values all the way through? Help? Thanks. function scan($random) { if ($random == 1) { $query = "SELECT * FROM users WHERE clicks > 20 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } else { scan(2); } } if ($random == 2) { $query = "SELECT * FROM users WHERE clicks > 10 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } else { scan(3); } } if ($random == 3 OR 4 OR 5) { $query = "SELECT * FROM users WHERE clicks > 0 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } } $random = rand(1, 5); scan($random); Please check the img link and you will understand Code: [Select] for ($index = 1; $index <= $numdays; $index++) { $users="SELECT invoice_date, DAY(invoice_date) as invoiceday, sum(total_amount) as fullamount from invoices WHERE MONTH(invoice_date)='".$month."' AND YEAR(invoice_date)='".$year."' GROUP BY invoiceday"; $res=mysql_query($users); $row=mysql_num_rows($res); while($fetch=mysql_fetch_array($res)){ echo "<tr id='". ( ( $j %2 == 0 ) ? 'row3' : 'row4' ) . "'>"; $explodedate=explode("-",$fetch['invoice_date']); $days=$explodedate[2]; $month1=$explodedate[1]; $year1=$explodedate[0]; $dates=date("jS", strtotime($fetch['invoice_date'])); echo "<td style='text-align:left;padding-left:12px'>".$index."</td>"; if($index==$dates){ echo "<td style='text-align:right;padding-right:12px'>".$fetch['fullamount']."</td>"; }else{ echo "<td style='text-align:right;padding-right:12px'>--</td>"; } echo "</tr>"; } } $total="SELECT SUM(total_amount) as fulltotal from invoices where MONTH(invoice_date)='".$month1."' AND YEAR(invoice_date)='".$year1."';"; $totres=mysql_query($total); $totfetch=mysql_fetch_assoc($totres); if($totfetch['fulltotal']==""){ echo "<tr><td>NOTHING FOUND</td></tr>"; }else{ ECHO "<TR>"; echo "<td style='color:#BD0000;padding-left:12px;border:1px solid #ccc;width:20%;height:40px;text-align:left'>TOTAL AMOUNT FOR ".$displaydate."</td>"; echo "<td style='color:#BD0000;border:1px solid #ccc;width:20%;height:40px;text-align:right;padding-right:12px'>".$totfetch['fulltotal']."</TD></TR>"; } echo "</table>"; Hi, I want to build into my html table that populates my database table to have a column for checkboxes with a delete button that takes the user to another page to confirm the deletion by outputting a message: Are you sure you want to delete ____, followed by a for loop to see how many checked records to get its ID in order to get its appropriate name. So I have a submit button with name attribute of "delete0" and the values of the input type of checkbox is $row['ID'], for some reason, I get the notice: "Notice: Undefined index: modifyArray in C:\display.php" and modifyArray is the name I give to the checkbox attribute (please see this in my display.php below) Here is my display.php Code: [Select] <table border="border"> <!--NB: checkbox form for multiple delete/update/insert--> <form method="post" action=""> <input type='submit' value='DELETE' name='delete0' /> <?php session_start(); require 'bellSessionDisconnect.inc'; require 'bellConnect.inc.php'; $result=mysql_query("SELECT ID, Image, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts"); //phpinfo(); //NB: print table headings if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { //$counter+=1; print "<table border='border'>"; print "<tr> <th>ID</th> <th>Select entries to modifiy</th> <th>Image</th> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> <th colspan='2' align='center'>Modify</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { //extract($row); "<tr align='center'> <td>$row[ID]</td> <td><input type='checkbox' name='modifyArray[]' value='$row[ID]' /></td> <td>"; if(!empty($row['Image'])) { $curImage=$row['Image']; } else if(empty($row['Image'])) { $curImage='fileUploadIcon.jpg'; //$title="please upload item image"; } print "<img src=$curImage width='70px' height='90px' /> </td> <td> $row[Name] </td> <td> $row[Manufacturer] </td> <td> $$row[Price]</td> <td align='left'>$row[Description]</td> <td>$row[SimSupport]</td> <td><a href='bellUploadForm.php?ID=$row[ID]'>UPLOAD IMAGE</a></td> <td><a href='bellUpdateForm.php?ID=$row[ID]'>UPDATE</a></td> </tr>"; //}//END INNER IF }//END WHILE }//END BIG IF ?> <?php if(array_key_exists('delete0', $_POST)) { $modifyArray=$_POST["modifyArray"]; if(!empty($modifyArray)) { header("Location: http://localhost/bellDeleteForm.php"); exit(); } } ?> </form> </table> I will worry about redirecting to bellDeleteForm.php to confirm the records the user wants to delete after I get this going, please help!!! thanks Hi, my PHP code currently outputs the results from a users search by querying a backend postgresql database. As result/row is retuned to the user i would like to be able to detect whether or not they have checked a checkbox at the end of each rown in which case multiple rows can then be deleted from the database upon the user clicking a 'delete multiple records' button. I have no problem in being able to display the checkboxes on the webpage but i am a little unsure as to how to refernce them and detect which ones the user has checked. Given my database stores hostnames/IP addresses would it be best to name each checkbox to reflect the hostname or name the value it returns when checked to reflect the hostname. Given the above and that I also store the results of a users search in a $_SESSION['hosts'][][] array how can I then tie the two together? Thanks for reading. When I log in to my website I am getting something like this in the URL... Code: [Select] http://local.debbie///////////articles/article.php?slug=postage-meters-can-save-you-money If I then navigate to other pages everything seems fine and I get a normal URL like this... Code: [Select] http://local.debbie/articles/consider-becoming-an-s-corporation What is going on?! Debbie can someone help to add new products and increase the quantity of the product when pressing the + button, but it works for [-] Code: [Select] <?php include "./php/connection.php"; function products () { $query = "SELECT * FROM product"; if (@mysql_num_rows($query)==0) { echo "There are no products to display!"; } else { while ($query_row = mysql_fetch_array($query)) { "<div class='product'>" . "<img class='img' src=". $row["Image"]." alt='phone' width='100' height='150' />" . "<p class='name'>".$row["Name"]."</p>". "<p class='price'>£". $row["Price"] ."</p>". "<p><a href='./cart.php?ProductID=". $row["ProductID"]."' class='myButton'>More Info</a></p>". "</div>"; } } } if (isset($_GET['ProductID'])) { $quantity = mysql_query('SELECT * FROM product WHERE ProductID = ' .$_GET["ProductID"]); while ($quantity_row = mysql_fetch_array($quantity)) { if ($quantity_row["Quantity"]!=@$_SESSION["cart_".$_GET["ProductID"]]) { @$_SESSION["cart_".$_GET["ProductID"]]+="1"; } } } if (isset($_GET["remove"])) { $_SESSION["cart_".$_GET["remove"]]--; header("Location: ./cart.php"); # Go back to the login pages } if (isset($_GET["delete"])) { $_SESSION["cart_".$_GET["delete"]]="0"; header("Location: ./cart.php"); # Go back to the login pages } function paypal_items() { $num = 0; foreach($_SESSION as $name => $value) { if ($value!=0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT ProductID, Manufacturer, model, Price FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$productid.'">'; echo '<input type="hidden" name="item_name_'.$num.'" value="'.$query_row['Name'].'">'; echo '<input type="hidden" name="amount_'.$num.'" value="'.$query_row['Price'].'">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">'; } } } } } function cart () { "<table id='producttable' border='1'>". "<tr>". "<td class='td top'>Delete</td>". "<td class='td top'>Product Name</td>". "<td class='td top'>Quantity</td>". "<td class='td top'>Price</td>". "<td class='td top'>Sub Total</td>". "</tr>"; foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT * FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $sub = $query_row["Price"] * $value; "<tr>". "<td class='td'><a href='./cart.php?delete=".$productid."'> [Delete] </a></td>". "<td class='td'>".$query_row["Manufacturer"]."</td>". "<td class='td'>".$value."</td>". "<td class='td'><a href='./cart.php?ProductID=".$productid."'> [+] </a>£".$query_row["Price"]."<a href='./cart.php?remove=".$productid."'> [-] </a></td>". "<td class='td'>£".$sub."</td>". "</tr>"; } } @$total += $sub; } } if (@$total==0) { echo "<p>Your basket is empty</p>"; } else { echo @" Total: £" .$total; ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="kamran193@hotmail.co.uk"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> <?php } echo "</table>"; } echo cart(); echo products(); ?> Code: [Select] $getrest = mysql_query("SELECT * FROM block WHERE sid='$id' ORDER BY `id` DESC",$this->connect); while($row1 = mysql_fetch_assoc($getrest)) { $idz = $row1['id']; $getmore = mysql_query("SELECT * FROM block WHERE sid='$idz' ORDER BY `id` DESC",$this->connect); while ($row2 = mysql_fetch_assoc($getmore)) { } } you see i'm using the result from the first query in the where clause of the second query. This isn't good practice as what i'm trying to accomplish could lead me doing this up to ten times. what would be a better way to do this than while loops inside of while loops? example? The code works but the title is repeated with each new set of data. I want the titles set up at the top and never repeating... No idea what is causing it.
$conn = new mysqli($servername, $username, $password, $dbname); $sql = "SELECT deadchar, level, class, killforumid, realm, date FROM pkdata ORDER BY deadchar DESC"; $result = $conn->query($sql); while($row = $result->fetch_assoc()) { $deadchar = $row['deadchar']; $level = $row['level']; $class = $row['class']; $killforumid = $row['killforumid']; $realm = $row['realm']; $date = $row['date']; $conn->close(); echo "<table><center><tr> <th> <font size=3 color=#070719>Victim</font> </th> <th> <font size=3 color=#070719>Level</font> </th> <th> <font size=3 color=#070719>Class</font> </th> <th> <font size=3 color=#070719>Killer</font> </th> <th> <font size=3 color=#070719>Realm</font> </th> <th> <font size=3 color=#070719>Date</font> </th> </tr></center>"; echo "<tr><center> <td><center>$deadchar</center></td> <td><center>$level</center></td> <td><center>$class</center></td> <td><center>$killforumid</center></td> <td><center>$realm</center></td> <td><center>$date</center></td> </tr>"; echo "</table>"; } ?> I don't even really know how to title it. I have this piece of code, i wrote. it works with wordpress api but honestly i don't think that matters much. what it does, is pick $ci number of categories, and then picks 2 posts from each category. it then assigns the image in/attached to that post to an array, to be used later. this all works fine, the problem is when it picks a post that doesn't have an image. right now, it can't tell that. writing in a bit to be able to tell whether there is an image or not should be easy. i'm thinking it can be as basic as file_exists or as complicated as parsing the post. the part i have the problem with - is how do i make it go back and pick another post/category when it comes up short? more than once? i want it to keep going back until it comes up with an image. i'd rather not expand the search any farther than necessary Code: [Select] <?php if ( false === ( $scroller = get_transient( $stransient ) ) ) { if (!is_array($scroller) || count($scroller)==0) { $args = array( 'type' => 'post', 'parent' => 18, 'exclude' => 63, 149, 278, 62 ); $companies = get_categories( $args ); while (count($companies) > $ci){unset($companies[array_rand($companies)]);} shuffle($companies);$truckco= array(); foreach ($companies as $company){ $argus = array('numberposts' => 2, 'orderby' => 'rand', 'post_type' => 'post', 'category' => $company->cat_ID ); $listings = get_posts($argus); foreach($listings as $tn=>$post) { $truckco[$company->slug]['truck_'. $tn]['image'] = get_the_image( array( 'image_scan' => true, 'format' => 'array', 'width' => '172', 'height' => '129' ) ); $truckco[$company->slug]['truck_'. $tn]['pid'] = $post->ID; } } ?> thank you Hi guys i am a complete novice learning. I want to automatically load a form page without using the submit button. i can get the page to load no problems but the url keeps refreshing in the browser window ? here is the code i am using.
<h3>View Mileage.</h3> <form method="post" action="testmileage.php" name="mileage" id = "mileage"> <input type="hidden" name="start-date" value="2020-04-06"> <input type="hidden" name="end-date" value="2021-04-05"> </form> <script>window.onload = function(){ document.mileage.submit(); };</script>
Hey, I'm not that familiar with PHP so maybe what I'm asking for is not even possible. I plan to establish a webserver that is connected to a RS232 device. I don't have any problems accessing the RS232 interface with a PHP-script, it's all working fine. Now I want the incoming data from the device being display on the servers webpage almost in realtime. When I say almost I mean that the client who is logged on to the website should be able to define the update rate of the incoming data. So here comes the problem, I need something like the java script setinterval() function that is working on the server-side and repeats the data request to the device in an infinite loop with the given time interval. I don't want to refresh the whole page as I will have to update about 20 sets of data within seconds! I found this code: http://phpclasses.chimit.nl/package/5544-PHP-Call-a-function-after-a-period-of-time.html it looks pretty promissing but I just can't make it working... As I said I'm a PHP-noob so I just put the code below on the start of my own code and provided the Timer.class.php file in my project folder. Could anyone explain how I could make the test function repeating endlessly on a 1sec basis using this code so I would get a screen full of "called"? So far I only get two "called" :-) Thanks! declare(ticks=100); function test () { print "<br>called"; } require_once 'Timers.class.php'; setTimeout('test', 110000000); setInterval('test', 10000000); sorry if i have posted this in the wrong place, wasnt sure wether to post here or mysql. I have made a php calendar, and i am now wanting it to show if there is an event on that day and if so show it in a tool tip. the tool tip is populated by what is in the title="" of the link so i need my events to be shown in there. I have figured out how to show the event but now i am stuck on how to show all events if there is more than one one that day, how i have set it seems to only the second event, probably as the second variable overwrote the first variable. this is the code i have at the minute .............. $result = mysql_query("SELECT * FROM events WHERE day='$day_num' AND month='$fullmonth' AND year='$year'") or die(mysql_error()); $rows= mysql_num_rows($result); if ($rows !="false"){ while($rowout = mysql_fetch_array($result)) { $todayis = $rowout['day'] ."-". $rowout['month'] ."-". $rowout['year'] ."<br>"; $title= $rowout['event'] ."<br><br>";} $firstl = "<a href='' title='". $todayis . $title ."'>"; $lastl = "</a>";} else {$firstl = ""; $lastl = "";} then to display the day and links ................. Code: [Select] <td><? echo $firstl; ?><? print $day_num; ?><? echo $lastl; ?></td> could some one be so kind and help me write it so that it displays all events? here is a link to the calendar, incase its needed. http://www.scripttesting.htmlstig.com/calendar/index.php Many thanks Carl I have a simple problem but seem to be hitting a roadblock with fixing it. I am in the process of upgrading a site from PHP 5.6 to 7.0 (eventually to 7.2) I am seeing error notices like PHP Notice: Undefined index: productpage in ….. I know this it because the $_REQUEST can sometimes be empty depending on what data is passed back and when certain pages are loaded $productpage = mysqli_real_escape_string($con, $_REQUEST['productpage']); I also know that I could turn the error notice off or use isset to check $_REQUEST but I would prefer to use the ?? '' option to fix this issue. The problem is that when I add the ?? '' option to the above code the problem resolved itself but then moments later the same error on the same line reappeared in the error logs and I cant understand why. Can someone give me the correct example of where to place ?? '' in the above code so that I can rule out my potentially dodgy code as being the reason the error keeps reappearing.
I know I am probably complicating this but I am looking for a way to code a header and footer to the exterme top and extreme bottom of my pages. I have seen it before but I have no idea how to do it from scratch. But I ore or less want to be able to edit my header or footer one time and it work every where. Thanks in advance. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310594.0 Hello coders, I'm using this code to grab random results from a table and it works well but I need it to be a non-repeating event. Code: [Select] $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `jobs_board` "); $offset_row = mysql_fetch_object( $offset_result ); $offset = $offset_row->offset; I'm using this query followed by the html which is a set of divs with inline echo statements for the various variables I've localised from the table. Then I'm repeating that process a number of times to create a small list (I wanted to use a single while loop but cant figure it out at the moment). Anways, how can I make it so each query is random but also not repeated? At the moment they are indeed random but sometimes one same entry will appear a number of times consecutively... Nice one guys, L-plate This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=329670.0 Hello Everyone, I'm using PHP with MySQL. One of the fields in the database is website. The code I'm using is as follows: variable: $web=mysql_result($result,$i,"web"); html/php code: <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> What it should do is have the clickable word Website with the correct url from the database. Instead it's repeating the website the page is on. For example it's doing this: http://mywebsite/www.enteredwebsite.com Any help is appreciated. Hello I am only new to this site (my first post) and I am also only new to PHP. I have a site designed call http://www.mediareviewzone.com and I am trying to modify it using PHP. What I am trying to do is when a option is selected in the navigation menu then it will get a variable which will be referenced with a SQL database and then repeated regions will be populated with the table data. For example if you select horror genre in the movies menu, horror will be saved into the url and then the repeated regions will only show the horror movies. The code I have so far is shown below. The repeat region works fine, the only problem I am having is the first if else statement. gen is the variable that would contain horror for the example described above. Thanks for your help and time, as I stated I am only a new to PHP and this is probably an easy question. Code: [Select] <?php if (isset($gen)){ $subject_set = mysql_query("Select * FROM movies WHERE genre ={$_GET['gen']}", $connection);} else{ $subject_set = mysql_query("Select * FROM movies", $connection); } if (!$subject_set){ die("Database connection failed: " . mysql_error()); } while ($subject = mysql_fetch_array($subject_set)){?> <div class="par_element"> <div class="par_element2"> <h2> <a href=" <?=$subject['link']?>"><?=$subject['title']?> Review</a></h2> <?= $subject['description']?> <a href=" <?=$subject['link']?>"> read more on <?= $subject['title']?>.</a></div> <a href="<?=$subject['link']?>"> <img src=" <?=$subject['picture']?>" alt="<?=$subject['title']?>" name="<?= $subject['title']?>" width="65" height="100" border="0" id="<?= $subject['title']?>" /></a> </div> <?php } ?> hi guys....i have a doubt on the checkbox use and validation in php.... how do you enable one checkbox and once it is checked the others would be disabled automatically....... is this possible in php or do we use javascript.... ur guidances and help is appreciated in advance |