PHP - Creating Output When Number Of Rows Gets To Each 10
Hey guys was wondering if anyone could modify the code below to have $output = 'yes' if the number of rows equal 10, 20, 30, 40, 50, 60, 70, 80......... etc
$dbhost = '******'; $dbuser = ''******';'; $dbpass = ''******';'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('MYSQL N/A - Please Contact Admin'); $dbname = ''******';'; mysql_select_db($dbname); $query="SELECT * FROM documentaryinfo"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close($conn); ?> Thanks -------------------------------------------------------------------------------------------------------- Watch Free Documentaries Online - The Documentary Database www.free-documentaries-online.com -------------------------------------------------------------------------------------------------------- Similar TutorialsHi I wanted to know how once I have selected and echoed the rows from mysql table how can I get it to number those rows that echo? etc 1. echo $variable 2. echo $variable 3. echo $variable 4. echo $variable 5. echo $variable Any help is appreciated I was just wondering when you run a mysql query what the easiest way to find out the number of rows returned. Just so I can do a number of results found on a search. Thanks. Hi, I have a problem regarding counting rows in a mysql table. Here is the code: Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect('read'); $check = 'SELECT COUNT(*) FROM images'; $checkRes = $conn->query($check) or die(mysqli_error()); if($checkRes <= 0) { header('Location: empty_blog.php'); // redirect to another page } else { // do something else... } ?> The error I'm getting: "Notice: Object of class mysqli_result could not be converted to int in C:\xampp\htdocs\photoblog\index.php on line 6" Any help is greatly appreciated! I have a cart script, and I need to display the products the user has added. This is a school assignment and I'm very stuck on this seemingly 'little' error. Right now, I have two tables: For time's sake, I am showing duplicate products with different prod_id's: Table: products prod_id category sub_category thumb_href image_href title desc summary manufacturer price 17 sofa leather red_leather_sofa_small.jpg red_leather_sofa_main.jpg Red Leather Sofa [BLOB - 134B] [BLOB - 59B] Balenty 999.99 18 sofa leather red_leather_sofa_small.jpg red_leather_sofa_main.jpg Red Leather Sofa [BLOB - 134B] [BLOB - 59B] Balenty 999.99 19 sofa leather red_leather_sofa_small.jpg red_leather_sofa_main.jpg Red Leather Sofa [BLOB - 134B] [BLOB - 59B] Balenty 999.99 And this is the cart table that holds temporary cart items (storing the product ID to pull later): Table: cart temp_cart_item cart_id (assigned by session_id() ) prod_id user_id 22 jier11u0e7cl2ghosjodpaark2 17 asdfasdf 23 jier11u0e7cl2ghosjodpaark2 17 asdfasdf 24 jier11u0e7cl2ghosjodpaark2 35 asdfasdf 25 jier11u0e7cl2ghosjodpaark2 5 asdfasdf 26 jier11u0e7cl2ghosjodpaark2 19 asdfasdf SO, user 'asdfasdf' is logged in and has selected 5 items for his cart - two of which are the same (prod_id 17). Basically, I need to compare the prod_id's of each table and output all products (and quantities) matching the temporary cart prod_id. What I have now to loop through and display the cart items are (bear with me): echo "<h1>Cart</h1>"; } // Display welcome and navigation links displayWelcome(); displayNav(); // Getting the prod_id's from the table cart to compare with the product table $cart_id = session_id(); $user_id = ($_SESSION['login_username']); $query = "SELECT prod_id FROM cart WHERE cart_id='$cart_id' AND user_id='$user_id'"; $result = mysqli_query($cxn,$query) or die("<h2 class=\"warning\">Whoa! Problem with the cart script here!</h2>"); $nrows = mysqli_num_rows($result); if($nrows < 1) { echo "<h2>Your cart is empty</h2><p><a href=\"catalog.php\">Go back to the catalog</a></p>"; } else { // Continue to gather products for all the product IDs in the products DB table... echo "<h4>$nrows items in your cart</h4>"; while($row = mysqli_fetch_array( $result )) { $user_id = ($_SESSION['login_username']); $product = $row['prod_id']; // Is the query my problem? $query = "SELECT * FROM products WHERE prod_id='$product'"; $result = mysqli_query($cxn,$query) or die("<h2 class=\"warning\">Whoa! Problem with the cart script here!</h2>"); $nrows = mysqli_num_rows($result); if($nrows < 1) { // If the item doesn't exist, display an error echo "<h2>That is not a valid product, or any of the items you had in your cart are missing or have been deleted.</h2><p><a href=\"catalog.php\">Go back to the catalog</a></p>"; // Protect from continually displaying an error by deleting the invalid cart record $deletequery = "DELETE FROM cart WHERE prod_id='$product'"; $deleteresult = mysqli_query($cxn,$deletequery) or die("<h2 class=\"warning\">Whoa! Problem with the cart script here!</h2>"); exit(); } while($row = mysqli_fetch_array( $result )) { // Then disply them in a table echo "<h2>Items in Your Cart:</h2>"; echo " <table id=\"products\"> <thead> <tr> <th class=\"col1 headercol\" scope=\"col\">Thumbnail</th> <th class=\"col2 headercol\" scope=\"col\">Summary</th> <th class=\"col3 headercol\" scope=\"col\">Manufacturer</th> <th class=\"col4 headercol\" scope=\"col\">Price</th> </tr> </thead> <tbody>\n"; $query = "SELECT SUM(price) FROM products WHERE prod_id='$product' GROUP BY price"; $priceResult = mysqli_query($cxn,$query) or die("<h2 class=\"warning\">Whoa! Problem with the cart script here!</h2>"); // keeps getting the next row until there are no more to get // Print out the contents of each row into a table echo "<tr> <td class=\"col1\">"; echo "<a class=\"imgHref\" href=\"detail.php?prod_id=".$row['prod_id']."\" title=\"".$row['title']."\"><img src=\"../images/".$row['thumb_href']."\" alt=\"".$row['title']."\" /></a>"; echo "</td>\n"; echo " <td class=\"col2\">"; echo "<h3 class=\"title\"><a href=\"detail.php?prod_id=".$row['prod_id']."\" title=\"".$row['title']."\">".$row['title']."</a> <span class=\"inlineh3\">by <a href=\"categories.php?manufacturer=".$row['manufacturer']."\" title=\"View all products by ".$row['manufacturer']."\">".$row['manufacturer']."</a></span></h3>"; echo "<p class=\"summary\">".$row['summary']."</p> <p class=\"descHeading\">&#9758; <em>Full Description:</em></p> <p class=\"desc\">".$row['desc']."</p>"; echo "</td>\n"; echo " <td class=\"col3\">"; echo "<p class=\"manufacturer\"><a href=\"categories.php?manufacturer=".$row['manufacturer']."\" title=\"View all products by ".$row['manufacturer']."\">".$row['manufacturer']."</a></p>"; echo "</td>\n"; echo " <td class=\"col4\">"; echo "<p class=\"price\">$".$row['price']."</p>"; echo "</td> </tr>\n"; } while($priceRow = mysqli_fetch_array( $priceResult )) { echo "<tr class=\"short\"><td class=\"col1\"><h3><a href=\"clear_cart.php\">Empty Cart</a></h3></td><td class=\"col2\"></td><td class=\"col3 nobackground\">Total:</td><td class=\"col4\">$".$priceRow[0]."</td></tr>"; } echo "</tbody> </table>"; echo "<p class=\"submitOrder\"><form action='submit_order.php' method='post' id='form'> <input type='submit' name='pButton' value='Submit Order'> <input name='order_total' type='hidden' id='order_total' value='".$priceRow[0]."' /> </form> </p>"; } } And so the cart.php looks something like this (this example asdfasdf has 6 items in his cart): So you can see that it only displays ONE item, even though asdfasdf DOES have 6 items in his cart (proven by checking database). And the price is not accurate, either. Can anyone help me in where my problem might be? Is it my query? Or my while clause? Folks, Having trouble here. Forgot how you use the COUNT. Not interested in the num_rows due to it being slow compared to COUNT. I have users table like this: id|username|sponsor_username 0|barand|requinix 1|phpsane|alison 2|mickey_mouse|requinix Now, I want to check if a sponsor username exists or not. Such as does the entry "requinix" exists or not in one of the rows in the "sponsor_username" column. In our example it does twice and so the variable $sponsor_username_count should hold the value "2". Else hold "0". I get error: Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
My code:
$stmt_1 = mysqli_prepare($conn,"SELECT COUNT(sponsor_username) from users = ?"); mysqli_stmt_bind_param($stmt_1,'s',$sponsor_username_count); mysqli_stmt_execute($stmt_1); //Show error if 'users' tbl was not successfully queried". if (!$stmt_1) { echo "ERROR 1: Sorry! Our system is currently experiencing a problem loading this page!"; exit(); } else { mysqli_stmt_bind_result($stmt_1,$sponsor_username_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Check if Sponsor Username in Url ($_GET) is already registered or not. If not then show "Invalid Url" or Link message. if ($sponsor_username_count < 1) { echo "<b>Invalid Url or Link!<br> Invalid Sponsor: \"$sponsor_username\"!</b><?php "; exit(); } }
Hi Guys! Trying to display data in 3 rows horizontally and 25 vertiacally Code: [Select] // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(biddersId)'] ." bidders logged."; echo "<br />"; } $query = "SELECT * FROM bidders ORDER BY biddersId"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Bidders</th>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo"<font face= \"calibri\" size=\"3\">"; echo $row['biddersId']; echo "</br>"; echo "</td><td>"; } echo "</table>"; ?> I have a html table displaying data from mysql database. I can count rows properly with mysql_num_rows but is there a way to echo which row number it is. What I want to do is count the rows ordered by cities and echo row number. Thanks for any help. Hi guys, is there anyway to process this $result from a mysql query inside PHP so that the data below will be formatted to a pivot-like table? The number of rows and columns of the output 'table' will be indefinite. Thanks so much! Data: ID Row Col Name 1 1 A A1 2 2 A A2 3 3 A A3 4 1 B B1 5 2 B B2 6 3 B B3 7 1 C C1 8 2 C C2 9 3 C C3 Results: A1(1) A2(2) A3(3) B1(4) B2(5) B3(6) C1(7) C2( C3(9) Hi Please take a look at my code snippet. I don't know how to get the number of rows returned from a MySQL stored procedure so that I can handle it accordingly. Any ideas please? Thanks Please help me. I'm fairly new to php and have been looking for answers on Goog for about two weeks or so with not an answer. This is my first post on a forum of any type. I have a form on a php page that when submitted sends a value to a confirm php page Code: [Select] <form action='buyconfirmorder.php' method='post'> Purchase: <input type='text' name='ask_shares'><br /><br /> You Will Pay:  <input type='text' name='ask'><br /><br /> <input type='hidden' name='postcardname' value='$postcardname'> <input type='submit' name='submit' value='Order'> </form> I need to take the users input from the form and subtract each row from a mysql DB one at a time until the users input is down to a remainder and then I need the remainder (I'll be working with the remainder as well). Code: [Select] $query = mysql_query(" SELECT * FROM ask, search WHERE search.id = ask.card_search_id AND search.card_name = '$postcardname' ORDER BY ask_price ASC"); The array will be numbers only. So an example would be: User input from the form is 100.00 Code: [Select] while($rows = mysql_fetch_array($query)) { $ask_price = $rows['ask_price']; } Let's say the array is 50.50, 40.50, 35.00 I need some code to do: 100.00 - 50.50 = 49.50 49.50 - 40.50 = 9.00 9.00 - 35.00 = <0 does not do anything so remainder = 9.00 would it be something like Code: [Select] $new_ask_shares = $_POST['ask_shares']; //some sort of a loop or array or combo of both ($new_ask_shares - $ask_price); the numbers are just an example as the actual numbers will be different each time I query my DB. Thanks in advance hello, all: I'm a newbie, and been trying to work out a way so that the results from an array (or mysql recordset for that matter), are nicely aranged in a table. I want them to show in a grid-like manner, with rows and columns added according to number of "items". I worked out this small code snippet, with a sample array, and for the life of me, cant figure out how to make it so it automatically "breaks" columns at 5 and start new row. I got it to show me right number of rows, but then it repeats all 10 names within them, as opposed to just showing 5 names in each row... Appreciate the help... Code: [Select] <?php $names = array('Charles','Henry','Manny','Philip','Rose','Evelyn','Peter','Julia','Cary','Sophia'); $numberColumns = 5; $numberNames = count($names); $numberRows = ceil($numberNames / $numberColumns); echo "<table border='1' width='400' cellspacing='0' cellpadding='0'>"; for ($i=1; $i<=$numberRows; $i++) { echo "<tr>"; foreach ($names as $name) { echo "<td>" . $name . "</td>"; } echo "</tr>"; } echo "</table>"; ?> ok, I'm not sure I know how to ask this question, but I've created a table that allows the user to add rows. The problem is, upon submit only the last row creates variables. How can I make sure every cell in every row sets a different variable? This is going to be a purchase order system. Here is my code: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Insert Table Row using DOM</title> <script language="javascript"> function addRow() { var tbody = document.getElementById("po_table").getElementsByTagName("tbody")[0]; var row = document.createElement("TR"); var cell1 = document.createElement("TD"); var cell2 = document.createElement("TD"); var cell3 = document.createElement("TD"); var inp1 = document.createElement("INPUT"); inp1.setAttribute("type","text"); inp1.setAttribute("name","quantity"); cell1.appendChild(inp1); var inp2 = document.createElement("INPUT"); inp2.setAttribute("type","text"); inp2.setAttribute("name","description"); cell2.appendChild(inp2); var inp3 = document.createElement("INPUT"); inp3.setAttribute("type","text"); inp3.setAttribute("name","unit_cost"); cell3.appendChild(inp3); row.appendChild(cell1); row.appendChild(cell2); row.appendChild(cell3); tbody.appendChild(row); //alert(row.innerHTML); } </script> </head> <body> <form method="post" action="review_po.php"> <table id="po_table" border="1"> <tbody> <tr> <th bgcolor="#c1c1c1">Quantity</th> <th bgcolor="#c1c1c1">Description</th> <th bgcolor="#c1c1c1">Unit Cost</th> </tr> <tr> <td><input type=text name="quantity"></td> <td><input type=text name="description"></td> <td><input type=text name="unit_cost"></td> </tr> </tbody> <tfoot> <tr> <th bgcolor="#e0e0e0">1</th> <th bgcolor="#e0e0e0">Shipping</th> <td><input type=text name="shipping"></td> </tr> <tr> <th bgcolor="#e0e0e0">1</th> <th bgcolor="#e0e0e0">Tax</th> <td><input type=text name="tax"></td> </tr> </tfoot> </table> <input type="button" value="Insert Row" onClick="addRow();"> <input type="submit" value="Review" name="review_po"> </form> </body> </html> right now it goes to this page: Code: [Select] <?php //convert to variables $quantity = $_POST['quantity']; $description = $_POST['description']; $unit_cost = $_POST['unit_cost']; $extended_cost = $_POST['extended_cost']; $shipping = $_POST['shipping']; $tax = $_POST['tax']; ?> <?php echo $quantity; ?><br> <?php echo $description; ?><br> <?php echo $unit_cost; ?><br> <?php echo $extended_cost; ?><br> <?php echo $shipping; ?><br> <?php echo $tax; ?><br> here is the page: http://po.shopphgmag.com/create_po.html Thanks for looking This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344772.0 I'm trying to create a website, that echo's out a bunch of groups, where each group contains a group of checkboxes, containing A value, and a label for the checkbox, the way it is created right now, is foreach that echo's out a bunch of php arrays, which was easier than the static way before - But still, it's static in some way, or not very user friendly at the moment.. My problem is that I really want to write it in a database when I have the option. Is there anyone that can give some tips how to do? At the moment, my foreach looks like this: Code: [Select] echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; /* NEXT WE CREATE OUR FOREACH LOOPS TO ECHO THE HTML FOR LOOKS AND CHECKBOXES */ $totalID=0; // this is a counter we use to build our check box names foreach ($items as $list){ $totalID++; // add one to the checkbox name counter echo "<h2>{$list['title']}</h2>\n"; // and echo out our section header foreach ($list['items'] as $cbox){ // now for each item in the list, call it $cbox // $cbox now holds the item name, and point value echo "<label class='checkbox'><input type='checkbox' name='totals[$totalID][]' value='{$cbox[1]}'> {$cbox[0]}</label>\n"; } } echo "</form>"; And my array is something like this: Code: [Select] $items['computers']['title']='Computer Brand'; $items['computers']['items'][]=array('Apple iMac',1); $items['computers']['items'][]=array('Apple Macbook',.5); $items['phones']['title']='Phone Brand'; $items['phones']['items'][]=array('iPhone',1); $items['phones']['items'][]=array('HTC',1); As said, I can write this, but takes time. I want to get it into a database, that data above, but I'm having problems about echo'ing it out, I really can't see how I should do. My current database looks like this: Thank you! I would like to create a Job Numbering system for all of my jobs. Job number format : print-001232 I would like the job numbers to be sequential. So we will have a drop down list with three categories. which will form the first part of the job number. (print- ) and then I would like the 6 digits after it to be sequential starting from 000001. What is the best way of going about doing this? Hi all, I have a database which contains customer details. We have a php script which pulls the records from the database and puts them into a table on the page. Currently, it fetches all the customer records. This wasn't such a problem when there was only a few customers in the db but this is a bit higher now! Is there any way I can modify the script to only show 20 per page and add links to page 2 etc along the bottom, which can be clicked to show the next 20 and so on? I can post my current code if need be, Thanks. Hi All,
I'm looking to update a mysql column weekly, where by 5 randomly selected rows are given a new random number, from between 1 and the num_rows / 5. This cycle is looped again until all the entries have a new random group for the week. It is to help mix up the players for teams for 5 aside. It needs to be able to accomodate the posibillity of the num_rows not dividing exactly by 5, using ceil perhaps?
As an example
Name Group
a 1
b 2
c 1
d 1
e 1
f 3
g 2
h 1
i 2
j 2
k 2
Then Next week
Name Group
a 2
b 1
c 2
d 2
e 1
f 2
g 3
h 1
i 2
j 1
k 1
I hope that makes sense. It'll be automated via cron job.
I've been really struggling with it, this is as far as I have got.
$totalgroupsraw = $num_rows /5; Create a data form that should accept odd number of words in a particular sentence
Input Example: I am working in retailon.
and should display the output as reversing first and last word and second word to fourth word
and so on and the middle word should be same and should also display the number of words.
Output Example: retailon in working am i.
words=5.
Input:I am Working in Google.
Output:Google in Working am I.
Words:5
I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? |