PHP - Moved: Fb Count Php Mysql
This topic has been moved to PHP Applications.
http://www.phpfreaks.com/forums/index.php?topic=344992.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321929.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312690.0 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? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320042.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306062.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342776.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313023.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=326580.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310377.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=343070.0 This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=351485.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312721.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330080.0 Hello 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: 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) { 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 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. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330871.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305934.0 |