PHP - Mysql Count -> Php Arrays
Hi everyone
I have a requirement to create some reports and outputting these to a PDF. I'm using FPDF which seems to be rather user-friendly. I was hoping someone could help with me a problem I have regarding MySQL COUNT and PHP arrays.
I have a table named 'faults' and within this a row called 'level'. There are three 'levels' = P1, P2, P3 that could populate this row. I wish to display the output into a PDF so it looks something like this:
Total number of faults;
P1 P2 P3
1 2 3
Where I'm falling short is how to perform the COUNT and then grab the data stick it into an array and output it to the PDF. The MySQL statement you see below, if put directly into phpMyAdmin, seems to do the trick, so I'm hoping I'm on the right track. So far I have this:
<----OUTPUT OMITTED----> $result=mysqli_query($con, "SELECT COUNT(IF(level='P1',1, NULL)) 'P1', COUNT(IF(level='P2',1, NULL)) 'P2', COUNT(IF(level='P3',1, NULL)) 'P3' FROM faults"); //initialize counter $i = 0; //Set maximum rows per page $max = 25; while($row = mysqli_fetch_array($result)) { //If the current row is the last one, create new page and print column title if ($i == $max) { $pdf->AddPage(); //print column titles for the current page $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,'Total P1s',1,0,'L',1); $pdf->Cell(50,6,'Total P2s',1,0,'L',1); $pdf->Cell(50,6,'Total P3s',1,0,'L',1); //Go to next row $y_axis = $y_axis + $row_height; //Set $i variable to 0 (first row) $i = 0; } //This bit definitely ain't right $p1 = $row['level']; $p2 = $row['level']; $p3 = $row['level']; $pdf->SetY($y_axis); $pdf->SetX(25); $pdf->Cell(50,6,$p1,1,0,'L',1); $pdf->Cell(50,6,$p2,1,0,'L',1); $pdf->Cell(50,6,$p3,1,0,'R',1); //Go to next row $y_axis = $y_axis + $row_height; $i = $i + 1; } //Send file $pdf->Output(); ?>Appreciate it must look a mess, but would appreciate someone cleverer than me pointing me in the right direction. Similar TutorialsHello again
Sorry, I come back cap in hand to ask for one last bit of help. After this I should be done never to bother you again.
I posted just previously regarding outputting the results of a MySQL COUNT query to a PDF file. Staying on that subject to an extent, I've been wracking my brains on why this conundrum isn't working. As before, I wish to display the information from one table but unlike before there are multiple rows as opposed to multiple columns.
I have my table 'faults' and wish to query the top ten, or top most occurring 'site_id' in this table. The following MySLQ query as before works just fine in phpMyAdmin:
"SELECT `site_id` AS `site`, COUNT(*) AS `count`
FROM `faults`
GROUP BY `site`
ORDER BY count(*) DESC;"
Not much in the DB right now but it yields the following as I expect:
Site Count
1 7
2 6
3 6
I was hoping getting this into a PDF wouldn't be so tricky but as usual I've come unstuck. Essentially what is happening is that it's only displays the bottom row, not all. Here's my code:
<?php require('pdf/fpdf/fpdf.php'); include('core/connect.php'); //Create new pdf file $pdf=new FPDF(); $pdf->Open(); //Disable automatic page break $pdf->SetAutoPageBreak(false); //Add first page $pdf->AddPage(); //Heading $pdf->SetFillColor(255,255,255); $pdf->SetFont('Arial','BU',12); $pdf->SetY(25); $pdf->SetX(25); $pdf->Cell(25,6,'Top Site:',9,0,'L',1); $result_topten = mysqli_query($con, "SELECT `site_id` AS `site`, COUNT(*) AS `count` FROM `faults` GROUP BY `site` ORDER BY count(*) DESC;"); while($row = mysqli_fetch_array($result_topten)) { $site = $row['site']; $num_faults = $row['count']; } $pdf->SetFillColor(192,192,192); $pdf->SetFont('Arial','B',10); $pdf->SetY(35); $pdf->SetX(25); $pdf->Cell(50,6,'Site',1,0,'C',1); $pdf->Cell(50,6,'Number of faults',1,0,'C',1); $pdf->SetFillColor(232,232,232); $pdf->SetFont('Arial','',10); $pdf->SetY(45); $pdf->SetX(25); $pdf->Cell(50,6,$site,1,0,'C',1); $pdf->Cell(50,6,$num_faults,1,0,'C',1); $i = $i++; //Send file $pdf->Output(); ?>Resulting output in the PDF: Top Site: Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? I have created a basic array by pulling values from a database but now need to count how many of the array values are 0. Here is my code so far: $qty_array = array(); $qty_array[0] = $product_row["WF_qty"]; $qty_array[1] = $product_row["SD_qty"]; $qty_array[2] = $product_row["DD_qty"]; $qty_array[3] = $product_row["CD_qty"]; $qty_array[4] = $product_row["PD_qty"]; $qty_array[5] = $product_row["SP_qty"]; $qty_array[6] = $product_row["VS_qty"]; $qty_array[7] = $product_row["RO_qty"]; $qty_array[8] = $product_row["PO_qty"]; $qty_count = count($qty_array); This is returning the value 9 as I expected but I am not sure how to change the count function so that I count values that are 0 and ignore the rest. Can anyone help? How do I find out how large a dimension of an array is? I have an array with an X and a Y coordinate, and in the 3rd dimension I store it as the value of an ID. so an array might be x,y,560; x,y,415, etc. I can run a counter within the loop to determine the total number of iterations of the loop, but that isn't an accurate picture of how large the 3rd dimension of the array is. I have a table with 5 records with the following "id_number" for each record in ASC order: 2, 6, 74, 86,87 There is one other field called "tag_number" and for each record in ASC order here is the data: 50670, 50077, 1234, 1235, 1236 I have a text field and if I search for a spastic "tag_number" I want to return the record but count and display what record like this: Record 3 of 5 The above 3 of 5 means I searched for "1234". I'm not sure what loop I need and how to count the records, any help would be great! Here is what I'm thinking: $id_number = 74; $result = db_query("select * from table order by id_number ASC"); $num_rows = mysql_num_rows($result); //this will provide how many records are in the table $result = db_query("select * from table where id_number = '$id_number' order by id_number ASC"); for ($i = 1; $i == $num_rows; $i = $i + 1) { if ($result['id_number'] == $id_number) { This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=344992.0 first i will show example, table messages containes user id, message, read. now i want to get all the messages from user id 1 and see how many of them have read as true. How can i do this, i'm using MYSQL so really i need a count thing month a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 1 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 [20] [21] 22 23 24 25 [26] 27 28 29 30 31 2 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 3 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 4 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 5 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 6 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 7 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 8 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 9 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 10 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 11 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 12 puudu 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; i need help .. with calculating how many days are between example: january = 1 ; day =23 to feb =2; day 23 in php ... how can i do that I know there has to be a better way to count how many entries I have in my mysql db than what I'm currently using. Let me just show you what I'm trying to do and it will make better sense. http://batads.com/display.php You see how I am echoing the number of each category on one page? I am sure the current script I am using is insanely inefficient and as my DB grows I think it will cause me problems. Any suggestions on how to do this more efficiently? Below is what is currently running that page. Thank you. Code: [Select] <td><h4>Public Ads</h4><br> <?php echo '<a href="browse1.php?cat=1">Bill Boards<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='1'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=2">Transportation<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='2'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=4">Shopping Centers<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='4'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=3">Posters / Signs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='3'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=5">Bus Stops<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='5'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=6"> Other-Public<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='6'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Event Sponsorship</h4><br> <?php echo '<a href="browse1.php?cat=7">Concerts<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='7'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=8">Fairs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='8'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=10">Sports<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='10'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=9">Trade Shows<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='9'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=11">Other-Event<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='11'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Online Ads</h4><br> <?php echo '<a href="browse1.php?cat=12">Banner Space<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='12' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=13">Social Media<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='13' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=14">Email Lists<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='14'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=15">Blog Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='15'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=16">Ezine Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='16'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1area.php?cat=17">Other-Online<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='17'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Print Ads</h4><br> <?php echo '<a href="browse1.php?cat=18">Magazine<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='18'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=19">Newspaper<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='19'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=20">Brochure<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='20'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=21">Press Release Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='21'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=22">Other-Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='22'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Broadcasting Ads</h4><br> <?php echo '<a href="browse1.php?cat=23">TV / Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='23'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=24">Radio<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='24'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=27">Movies<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='27'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=25">Mobile Phone<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='25'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=28">Cinema<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='28'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=26">Press Release TV<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='26'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=29">Other-Broadcast<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='29' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Commercial Space</h4><br> <?php echo '<a href="browse1.php?cat=33">Private Property<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='33'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=34">Vehicle Wrap<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='34'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=35">Front Yard<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='35'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=36">Self Promotion<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='36'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=37">Other-Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='37'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Business Ads</h4><br> <?php echo '<a href="browse1.php?cat=30">Window Display<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='30'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=31">Interior Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='31'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=32">Point of Sale Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='32'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=41">Other-Business <a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='41'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </td> <td><h4>Misc</h4><br> <?php echo '<a href="browse1.php?cat=38">Creative Advertising<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='38'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=39">Video Games<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='39'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=40">Other-Misc<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='40'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> </td> </tr> </table> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321929.0 hello, I have a search that matches users ISBN with two databases....code is below $query_search_exact_match = mysql_query("SELECT nvc_site.title, nvc_site.id, nvc_site.description, nvc_site.search_text, nvc_site.image, nvc_site.date, nvc_site.price, nvc_site.location_city, nvc_site_ads_extra.name, nvc_site_ads_extra.value, nvc_site_ads_extra.classified_id FROM nvc_site,nvc_site_ads_extra WHERE name = 'ISBN%3A' AND live=1") or die(mysql_error()); then i take the ISBN that the user entered and match that with the isbn's in the DB while ($fetch_extra = mysql_fetch_array($query_search_exact_match)) { $value = ereg_replace( "[^0-9]", "", $fetch_extra['value'] ); $to_find_isbn = mysql_real_escape_string(ereg_replace( "[^0-9]", "",$_POST['szs'])); if($value == $to_find_isbn) { echo "Match Found"; } else { echo "No Match Found"; } //ELSE doesn't work here.....it displays both the if and else at the same time } i need it to display no match found if there was no match found.....I am soo lost right now!! please help thank you This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312690.0 Hello, I am trying to create article directory for learning PHP MySql and i want to write a script for recording number of views for an article and store it in Database. Can anyone please direct me to a nice simple tutorial or help me with the steps or algorithm? Suppose the link for an article is http://www.domain.com/article.php?id=123 Do i need to put extra variables and create a tracking PHP file for it? Hello there, i'm not sure if this goes to mysql, or this section, but since it's PHP based, i would say here. So, here's the thing, i have full set up table that reads from mysql database and display it as table. Everything is working just fine, even "order" buttons that i made, now i would like to have below the table some counts, for example: My table name "canonkickoff" has column named "Prevoz" which contain only Yes and No answers, i would like to see below the table how much "Yes" answers are inside the column. Also i have other column called "VelicinaMajice", which contain 6 different answers ( XS, S, M, L, XL, XXL ), i would like to see (again, below the table) how much of every has been answered. Like: There a XS = 6 S = 1 M = 2 L = 3 And 32 answered with Yes. Could anyone help me out? Here's the full php table: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>CanonKickOff 2012 Tabela.</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="table.css" type="text/css"> </head> <body style="margin: 0 0 0 0;"> <? include("passwd.php"); @$start = $_GET["start"]; if($start =='') $start =0; include("lib.php"); $link = mysql_connect($host,$username,$password); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($db, $link); if (!$db_selected) { die ("Can't use $db : " . mysql_error()); } //total number of records in the table $orderBy = array('Kompanija', 'id', 'ImePrezime', 'Email', 'Prevoz', 'VelicinaMajice', 'SlazemSe'); $order = 'id'; if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) { $order = $_GET['orderBy']; } $res = mysql_query("SELECT * from `$table` ORDER BY '.$order"); $res2 = mysql_query("SELECT * from `$table` "); @$rows = mysql_num_rows ($res2); $result = mysql_query("SELECT * from `$table` ORDER BY $order limit $start,40"); if (!$result) { die('Invalid query: ' . mysql_error()); } echo 'Sortiraj Po: <br>'; echo '<a href="?orderBy=id">ID:</a> '; echo '<a href="?orderBy=ImePrezime">Ime i Prezime:</a> '; echo '<a href="?orderBy=Kompanija">Kompanija:</a> '; echo '<a href="?orderBy=email">Email adresi:</a> '; echo '<a href="?orderBy=Prevoz">Prevoz:</a> '; echo '<a href="?orderBy=VelicinaMajice">Velicina majice:</a> '; echo '<a href="?orderBy=SlazemSe">Slazu se:</a> '; echo "<p align=center class = 'menu'> Ocitana tabela: $table </p>"; $cols = mysql_num_fields($result); $records = mysql_num_rows ($result); echo "<table align='center' width='1200' >"; echo "<tr bgcolor='BBCCDD' class='menu'>"; for ($i = 0; $i < $cols;$i++) { echo "<td align='center'>".mysql_field_name($result,$i)."</td>"; } echo "</tr>"; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr bgcolor='F6F6F6' class='normal'>"; foreach ($row as $value) { echo "<td align='center'>".$value ."</td>"; } echo "</tr>"; } $end = $start + $records; echo "<tr align = 'center' bgcolor = 'BBCCDD' class='menu'><td colspan=$cols> $start do $end od ukupno: $rows </td></tr>"; echo "<tr align = 'center' class='mylink'><td colspan=$cols> "; if($start != 0) { $prev = $start - 40; echo "<a href='tabela.php?start=$prev'> Prethodna </a> "; } if($start<$rows-10) { $next = $start + 40; echo "<a href = 'tabela.php?start=$next'>Sledeca</a> "; } echo "</td></tr>"; echo "</table>"; ?> </body> </html> The following works, but I don't want to have to write 50 query statements for 50 states. How can I just write one query (using a variable I presume) and then echo the variable count each time for each state? I'm just trying to list the total number of rows for each state, that exist in the db. <? $result = mysql_query("SELECT * FROM mytable WHERE source = 'alabama'") or die(mysql_error()); $num_rows = mysql_num_rows($result); ?> href="/state/alabama/">alabama</a> (<?php echo("$num_rows");?>) <br> <? $result = mysql_query("SELECT * FROM mytable WHERE source = 'alaska'") or die(mysql_error()); $num_rows = mysql_num_rows($result); ?> href="/state/alaska/">alaska</a> (<?php echo("$num_rows");?>) <br> The above would give output such as: alabama (122) alaska (212) is it possible to save it this way? I found no errors but there are also no effect in my db. help me guys! thank you. "while ($row = mysql_fetch_array($query)) { echo "<tr>"; echo '<td><input type="hidden" name="se_Id['.$i.']">'.$row['se_Id'].'</td>'; echo '<td><input type="hidden" name="user_Id['.$i.']">'.$row['user_Id'].'</td>'; echo '<td><input type="hidden" name="course_Id['.$i.']">'.$row['course_Id'].'</td>'; echo '<td><input type="hidden" name="ap['.$i.']">'.$row['ap_Id'].'</td>'; echo "<td>". $row['user_Fname']."</td>"; echo "<td>". $row['user_Lname']."</td>"; echo "<td></td>"; echo "<td></td>"; echo "<td>".$row['se_Yearlevel']."</td>"; echo "<td></td>"; echo "<td></td>"; echo "<td></td>"; echo "<td> <input type='checkbox' id='checkbox".$i."' value ='checked' onclick='checkbox_disabled(\"checkbox".$i."\",\"textbox".$i."\",\"checkbox".$i."2\");'></td>"; echo "<td><input type='checkbox' id='checkbox".$i."2'>"; echo " <input type='text' id='textbox".$i."'></td>"; echo "</tr>"; $i++; } } else { echo "No students enrolled"; } echo "</form>"; echo "</table>"; echo "<br></br>"; echo " <input type='submit' name = 'submit' value='Submit'>"; ?> <?php if (isset($_POST['submit'])) { foreach ($_POST['user_Id'] as $key => $user_Id) { $se_Id = $_POST['se_Id'][$key]; $status = $_POST['status'][$key]; $course = $_POST['course'][$key]; $officeid [$key]; $ap = $_POST['ap'][$key]; mysql_query("INSERT tbl_data (user_Id,se_Id,office_Id,course_id,ap_Id,Status) VALUES ('$user_Id','$se_Id','$officeid','$course','$ap','$status')") or die(mysql_error()); // echo "<meta http-equiv=\"refresh\"content=\"0;URL=offcourse_view.php\">"; echo "congrats"; } } ?>" I have a problem that i'm not quite sure how to do. I have to create a system that allows me to enter several postcodes associated with a particular event. (These are 4 digit postcodes). Somebody then has to enter a Postcode and it should pull up all events associated with that postcode. The problem being that each event (For i can't see another way of storing it easily) will have the postcodes stored in a mysql database in an array. How do i get SELECT to search through the postcode arrays and then print out any rows that have that particular postcode in it. Hey guys, i am having a problem and for the life of my i can't think of how to get around this problem. All the variables below are arrays and the code below is what i have done so far. The problem is when updating the records it only puts in "Array" in all of the fields being updated. How should i go about re-doing it so that when the first array in $idnumber is called. All the other arrays (Date, Description, Name) have their 1st array information allocated to a variable?? Code: [Select] $Date = $_POST['Date']; $Name = $_POST['Name']; $Description = $_POST['Description']; $idnumber = $_POST['ID']; $con = mysql_connect("localhost","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Picture_Blog", $con); foreach ($idnumber as $ID) { mysql_query("UPDATE slidorion SET Name = '$Name' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Description = '$Description' WHERE ID = '$ID'"); mysql_query("UPDATE slidorion SET Date = '$Date' WHERE ID = '$ID'"); } I insert data in mysql table row using multiple method : 1#2#3 . 1 is ID of country, 2 is Id of state, 3 is ID of town . now i have this table for real estate listings. for each list(home) i have country/state/town (1#2#3). in country table i have list of country - in country table i have list of state - in country table i have list of town. i need to The number of houses in country / state / town . my mean is : Code: [Select] USA [ 13 ] <!-- This Is equal of alabama+alaska+arizona --> ----Alabama [8] <!-- This Is equal of Adamsville+Addison+Akron --> -------Adamsville [2] -------Addison[5] -------Akron[1] ......(list of other City) ----Alaska [ 3 ] -------Avondale[3] ......(list of other City) ----Arizona [ 2 ] -------College[2] ......(list of other City) Lisintg Table : Code: [Select] ID -- NAME -- LOCATION -- DATEJOIN -- ACTIVE 1 -- TEST -- 1#2#3 -- 20110101 -- 1 2 -- TEST1 -- 1#2#3 -- 20110101 -- 1 3 -- TEST2 -- 1#3#5 -- 20110101 -- 1 4 -- TEST3 -- 1#7#6 -- 20110101 -- 1 Country Table : Code: [Select] id -- name 1 -- USA stats Table : Code: [Select] id -- countryid -- name 1 -- 1 -- albama 2 -- 1 -- alaska 3 -- 1 -- akron town Table : Code: [Select] id -- countryid -- statsid -- name 1 -- 1 -- 1 -- adamsville 2 -- 1 -- 1 -- addison 3 -- 1 -- 1 -- akron Thanks For Any Help. I am trying to figure out the best way to record page impressions in my MySQL database. This count will be coming from multiple websites and webpages, so could be millions per day. |