Jump to content

Search the Community

Showing results for tags 'row'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 9 results

  1. Say I have a records table with multiple records. There could be multiple records with the same name but different amounts. For Eg. Looking at the table below, the results should retrieve newest record-1 and record-2 because their amount is equals to or greater than 5.00. Record-3 is not selected because it falls below 3.00. record_id record_name record_amount 1 record-1 4.00 2 record-1 3.00 3 record-2 2.00 4 record-1 5.00 5 record-2 6.00 6 record-3 3.00 $get_records = $db->prepare("SELECT record_id, record_name FROM records WHERE record_amount >= :record_amount ORDER BY record_id DESC"); $get_records->bindValue(':record_amount', 5.00); $get_records->execute(); $result_records = $get_records->fetchAll(PDO::FETCH_ASSOC); if(count($result_records) > 0) { foreach($result_records as row) { $record_id = $row['record_id']; $record_name = $row['record_name']; echo $record_name; } } Currently the query above outputs ALL the rows that matches the >=. What I want to do is select only ONE row of each unique record name that matches the criteria. And that row is typically the last row that was inserted. So the output would be like only these two. How do I do that? 4 record-1 5.00 5 record-2 6.00
  2. Hello guys, I have a page named compare.php with two dropdown lists wich are populated with same values from a specific table. Now what i want to do is when a user is selecting one value from the first dropdown and another value from the secound dropdown to be redirected to a page lets say compare-items.php?id=1&id=2 and here in two different cols to get the values for the items, in the first col the values for the first item, and in the secound col the values from the sec item. How can i achive that? Thank you very much!
  3. So I have a simple script that adds and returns mysql data without refreshing the page. Everything works as it should. The only issue that I've noticed is that if I login as a user and insert a record(text) the FIRST time, it won't return that record in the row below. Not until I refresh the page. Now if I delete that record and insert a new record, it will then automatically return the record without the page refresh, as it should. Can you tell me why this is happening? Here is my js code. <script> $(document).ready(function(){ var recordId = $("#record-id").val(); function showRecord(){ $.ajax({ type: "POST", url: "bid-actions.php", data: "recordId="+recordId+"&action=showRecord", success:function(data){ $(".show-records").html(data); } }); } showRecord(); $(document).on('click','#record-submit',function() { var message = $("#message").val(); var recordId = $("#record-id").val(); $.ajax({ type: "POST", url: "bid-actions.php", data: "message="+message+"&recordId="+recordId+"&action=insertRecord", success:function(data){ showRecord(); $("#message").val(''); } }); }); }); </script> Html code. <div id="record-submit-form"> <input type="hidden" id="record-id" value="<?php echo $record_id; ?>"> <textarea id="message"></textarea> <input type="button" id="record-submit" value="Submit"> </div> <div class="show-records"> </div>
  4. Below is my code that is suppose to insert and show records from database using ajax. Retrieving the records from the database works. However it won't insert a record. I do not get any errors. The page simply refreshes when I hit submit button. Can you see what might be wrong in my code? index.php <script> $(document).ready(function(){ function showComment(){ $.ajax({ type:"post", url:"process.php", data:"action=showcomment", success:function(data){ $(".wrapper").html(data); } }); } showComment(); $("#submit").click(function(){ var name=$("#name").val(); var message=$("#details").val(); $.ajax({ type:"post", url:"process.php", data:"name="+name+"&details="+message+"&action=addcomment", success:function(data){ showComment(); } }); }); }); </script> $id = $_GET['id']; $title = $_GET['title']; $_SESSION['id'] = $id; $_SESSION['title'] = $title; <div class="wrapper"></div> <form action="" method="post" enctype="multipart/form-data"> <div class="newfield"> <label for="title">Name <span class="highlight">*</span></label> <input id="name" type="text" name="name"> </div> <div class="newfield"> <label for="details">Details <span class="highlight">*</span></label> <textarea id="details" name="details""></textarea> </div> <input type="submit" name="submit" id="submit" value="Submit Tale"> </form> process.php <?php require_once '/core/init.php'; $id = $_SESSION['id']; $action = $_POST['action']; if($action == 'showcomment') { try { $get = $db->prepare("SELECT * FROM sub_posts WHERE id = :id"); $get->bindParam('id', $id); $get->execute(); $getStmt = $get->fetchAll(PDO::FETCH_ASSOC); if(count($getStmt) > 0) { foreach($getStmt as $row) { $new_name = $row['name']; $new_details = $row['details']; ?> <ul> <li> <?php echo $new_name; ?> </li> <li> <?php echo $new_details; ?> </li> </ul> <?php } } else { // no records found. } } catch(Exception $e) { die($e->getMessage()); } } else if($action == 'addcomment') { $name = $_GET['name']; $details = $_GET['details']; try { $insert = $db->prepare("INSERT INTO sub_posts(id, name, details) VALUES(:id, :name, :details)"); $insert->bindParam('id', $id); $insert->bindParam('name', $name); $insert->bindParam('details', $details); $insert->execute(); if($insert == false){ echo 'record could not be inserted.'; } else { echo 'record has been inserted.'; } } catch(Exception $e) { die($e->getMessage()); } } else { echo 'no results.'; }
  5. So I've followed this code, corrected about 12 error, talked to my hosting and I am so done. I have tried everything but the error won't go away. The code is pasted below. As it's really late any help would be appreciated that would make my day the next day... <?PHP //connect to server $connect = mysql_connect("localhost","cello10_import","brigite27"); //connection to database mysql_select_db("cello10_import"); //query the database $query = mysql_query("SELECT * FROM users WHERE cover_image = 'http://d1w7fb2mkkr3kw.cloudfront.net/assets/images/book/small/9781/2500/9781250038821.jpg' "); //fetch the results / convert into array WHILE($rows = mysql_fetch_array(query)): $cover_image = $rows['cover_image']; $title = $rows['title']; $author = $rows['author']; echo "$cover_image<br>$title<br>$author<br><br><br>"; endwhile; ?> The error experienced is: Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in /home/cello10/public_html/display.php on line 10 Thanks for your help
  6. hi all , I have a table that shows all rows of a selected table . problem is that I want to delete marked rows from this table but this code is not working for me . updating code works fine but I can't delete selected rows . <? if($_SESSION["count"]!=0){ ?> <!-- begining of setting levels informations --> <form name="form2" method="POST" dir="rtl" action="" style="font-family:'B_yekan';"> <input name="level" type="hidden" value="<? if(isset($_POST['level'])){ echo $_POST['level'];} ?>"/> <div align="center" width = 615> <table class="styled-table" cellspacing="0" width="800" border="1"> <tr> <th width="10" scope="col" ></th> <th width="60" scope="col">level</th> <th width="60" scope="col">time</th> <th width="60" scope="col">date</th> <th width="42" scope="col">status</th> <th width="54" scope="col">price</th> <th width="42" scope="col">off</th> <th width="54" scope="col">off 2</th> <th width="60" scope="col">mark</th> </tr> <?php $id = array(); while($rows=mysql_fetch_array($result)){ $id[]=$rows['id']; ?> <tr> <td align="center"><input class="styled-input" type="hidden" name="id[]" id="id" value= "<? echo $rows['id']; ?>" /></td> <td align="center"><input class="styled-input" type="lev" name="lev" id="lev" value="<? echo $tbl_name; ?>" /></td> <td align="center"><input class="styled-input" type="text" name="time[]" id="time" value= "<? echo $rows['time']; ?>" /></td> <td align="center"><select class="styled-input" type="text" name="date[]" id="date" /> <option selected="selected" value="<? if($rows['date']=="1"){echo "1";}else{echo "0";}?>"> <? if($rows['date']=="1"){echo "even";}else{echo "odd";}?></option> <option value="<? if($rows['date']=="1"){echo "0";}else{echo "1";}?>"> <? if($rows['date']=="1"){echo "odd";}else{echo "even";}?></option> </select></td> <td align="center"><select class="styled-input" type="text" name="act[]" id="act" > <option selected="selected" value="<? if($rows['act']==1){echo "1";}else{echo "0";}?>"> <? if($rows['act']==1){echo "enable";}else{echo "disable";}?></option> <option value="<? if($rows['act']==1){echo "0";}else{echo "1";}?>"> <? if($rows['act']==1){echo "disable";}else{echo "enable";}?></option> </select></td> <td align="center"><input class="styled-input" type="text" name="price[]" id="price" value= "<? echo $rows['price']; ?>" /></td> <td align="center"><input class="styled-input" type="text" name="offprice[]" id="offprice" value= "<? echo $rows['offprice']; ?>" /></td> <td align="center"><input class="styled-input" type="text" name="off2price[]" id="off2price" value= "<? echo $rows['off2price']; ?>" /></td> <td align="center"><input class="styled-input" style="padding: 5px;width:20px" type="checkbox" name="checkbox[]" id="checkbox[]" /></td> </tr> <?php }//end of loop ?> </table> </div> <input class="styled-button-8" type="Submit" value="submit" name="Submit" /> <input class="styled-button-8" type="Submit" value="delete" name="delete" /> <?php }//end of if ?> </form> <?php // Check if button name "Submit" is active, do this if(isset($_POST['Submit']) && $_POST['Submit'] == 'submit') { for($i=0;$i<$_SESSION["count"];$i++) { $sql1="UPDATE `".$tbl_name."` SET `time`='".$_REQUEST['time'][$i]."',`date`='".$_REQUEST['date'][$i]."',`act`='".$_REQUEST['act'][$i]."' , `price`='".$_REQUEST['price'][$i]."' , `offprice`='".$_REQUEST['offprice'][$i]."', `off2price`='".$_REQUEST['off2price'][$i]."' WHERE `id`='".$_REQUEST['id'][$i]."' "; $result1=mysql_query($sql1); } if(isset($result1)){ $_SESSION["count"]=""; ?> <script language="javascript">alert('all of the rows updated successfully');</script> <?php print(redirect('regmanage.php')); } ?> <!-- deleteing records --> <?php // Check if button name "Submit" is active, do this if(isset($_POST['delete']) && $_POST['delete'] == 'delete') { for($i=0;$i<$_SESSION["count"];$i++) { if(isset($_POST['checkbox'][$i])){ $del_id = $_POST['checkbox'][$i]; $sql1 = "DELETE FROM `".$tbl_name."` WHERE `id`='".$_REQUEST['id'][$i]."' "; $result1= mysql_query($sq1) or die(mysql_error()); } } } if(isset($result1)){ ?> <script language="javascript">alert('the selected row deleted successfully.');</script> <?php print(redirect('regmanage.php')); } ?> <!-- end of setting infromations -->
  7. I am looking to alternate the row color on this loop I have. I have looked up a couple things through google, but none of them seem to fit into what I have. Let me know if this is simple or any suggestions on how to do this. Here is my code: $fields = array('RefNumber'=>'Reference Number','Status'=>'Status','Rep'=>'Rep','Disposition'=>'Disposition','appNumber'=>'appNumber', 'Con_Number'=>'Contract Number','Finance_Num'=>'Finance Number','Phone_Num'=>'Phone Number','Disc_Amount'=>'Discount Amount', 'Total_Cost'=>'Total Cost','Total_MP'=>'Total Monthly Payments','New_MP_Amt'=>'New MP Amount','New_DP_Amt'=>'New DP Amount','Notes'=>'Notes'); // start table and produce table heading echo "<table>\n<tr>"; $color1 = "#EFEFEF"; $color2 = "#FBFBFB"; foreach($fields as $legend){ echo "<th>$legend</th>"; } echo "</tr>\n"; // output table data while($row = sqlsrv_fetch_array( $result,SQLSRV_FETCH_ASSOC)) { echo "<tr>"; foreach($fields as $key=>$not_used) { echo "<td>$row[$key]</td>"; } echo "</tr>\n"; } echo "</table>\n"; $color1 & $color2 are the background colors I want to alternate on each row.
  8. Hello, I have a table that I read in from a postgresql database but I need to add a column that has checkboxes in the final row. It is for a shop so then when the item is selected via checkbox I can then press an add to cart button and send this using an array to the cart.php page. Firstly I need to be able to add checkboxes to the end of each row before I can even do that and I am struggling at how to get a checkbox at the end of each row of my table. <form action="index.php" method="post"> <table> <tr> <th>ref</th> <th>title</th> <th>platform</th> <th>description</th> <th>price</th> <th>select</th> </tr> <?php $resource = pg_query ($connect, "select refnumber,title,platform,description,price from CSGames"); while ($row = pg_fetch_array ($resource)) { $result[] = $row; } foreach($result as $key => $value) { echo "<tr>"; for ($j = 0; $j < pg_num_fields ($resource); $j++) { echo "<td>".$a[$j]."</td>"; } echo "</tr>"; } ?> </table> Could any help with this and explain so I can understand what is occurring in the future please?
  9. Bonjour, Been hunting the internet to find a solution myself, but instead thought I'd just ask on here. After all, if you don't ask, you don't get. Basically, I am creating a internal web based e-mail generator for the company I work for, that will send an e-mail to 'handover' certain 'tasks' to the next team on the next shift - It will be used internal only, so please excuse some of the sloppy coding but we only need it to 'work' - Doesn't really matter how! Anyway, the when someone goes through the form, they are given the options to add 'tasks' to the e-mail, these 'tasks' gets stored into a MySQL database, with the 'DONE' value of '0', ready for when the next person goes to generate the 'handover' - When the next person goes to generate the 'handover', they get a list of the 'tasks', that were previously inserted, by the previous person. Like so: They are given the option to mark the task as done, or not. Now here's the part where I get stuck... The subsequent 'handover' queries the MySQL database to see which 'tasks', have a 'DONE' value of '0' (not done). It then lists them. Here is the code: $toq2= mysql_query("SELECT * FROM tasks WHERE done='0'"); $toq2p = mysql_fetch_array( $toq2 ); $toq2r = mysql_num_rows( $toq2 ); if ($toq2r >= 1) { echo "<table border='0'><tr><td></td><td></td><td></td><td><img src='/assets/tick.png' width='20px' height='20px' border='0' /></td>"; $toq4= mysql_query("SELECT * FROM tasks WHERE done='0'"); while($toq4p = mysql_fetch_array( $toq4 )) { echo "<font color='black' size='2'><tr><td><font size='2'><strong>{$toq4p['system']}</strong></font> - </td><td><font size='2'><em>{$toq4p['region']}</em></font> - </td><td><font size='2'>{$toq4p['description']}</font></td><td><input type='checkbox' name='todo1[]' value='1'></td></font></tr>"; } echo "</table><br />"; } else { echo "<h3><font color='red'>NOTHING TO HANDOVER</font></h3>"; } Problem I have, is that because the amount of tasks is never consistent, I can't have a set query for the amount of values, therefore I need to find a way to dynamically set each row to update the 'done' value in the MySQL table to '1' if the box is ticked and leave it as '0', if the box isn't ticked. I hope I've explained myself well enough and appreciate any help that anyone can provide. Many thanks, P.S: Tasks are created as needed and are NOT in a schedule.. as so: When inserted from here, the value of 'done' is set to '0' - From the task list (picture in original post), if the person ticks the checkbox, I want it to be able to update that value of 'done' to '1'.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.