PHP - Add Count To Each Result
Hello all, I'm struggling adding a count result to this script. I want each result to be an id so I can place x amountof images in one position and the remaining in another position. Each user might have different awards so just using the award_id is no good as there will be empty space so I need the actual result to display a id number. Code: [Select] $res = mysql_query("SELECT award, image FROM awards WHERE active = '1'"); $codes = array(); while ($row = mysql_fetch_assoc($res)){ $codes[$row['award']] = $row['image']; } $userid = '1'; $res = mysql_query("SELECT * FROM user_awards WHERE user_id = '$userid'"); $row = mysql_fetch_assoc($res); foreach ($codes as $award => $image){ if ($row[$award] == 1){ echo "<img src=../$image><br/>"; } } Similar TutorialsI echo number of mysql rows. But every second outputted number is position higher than normally. How to fix that? 4,5 are normal then 6 is like 5px higher, 7 is normal, 8 is higher, 9 is normal etc. Any ideas? $result = mysql_query("SELECT * FROM `friend_system` WHERE `friend_system_accepter` = '$myusername' "); echo mysql_num_rows($result);This displays the total rows in the table. $result = mysql_query("SELECT COUNT(friend_system_accepter) FROM `friend_system` WHERE `friend_system_accepter` = '$myusername' "); echo mysql_num_rows($result);This displays '1', which is incorrect. I want to echo out the number of rows where 'friend_system_accepter' = $myusername Thanks PHP/MYSQL - - - Thank you in advance for any help. Quick question. I am calc'ing whether each line db output is a win/loss/tie below. Outputting $res in each line. Is there a simple way to COUNT the number of instances where $ res = "win" or loss or tie? I'd like to put an "overall" record at the top of the output. For example, for a given query, this chosen team's record is x WINS, Y Losses, Z TIES. Win/Loss/Tie is NOT a field in the db table. I know how to pull the total # of records pulled, but not this. Example User pulled a certain team to see game scores. 7 - 3 - 2 is their record. is what i'm trying to figure out Game Result Score Score opp Date game10 WIN * 7 2 blah game11 LOSS* 2 3 .... .... Code: [Select] //winloss begin works * above is a result of this code if ($row['sch_uba_score'] > $row['sch_opp_score']) $res = 'Win'; elseif ($row['sch_uba_score'] < $row['sch_opp_score']) $res = 'Loss'; else $res = 'Tie'; // winloss end works 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 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles Hey All, I need to count and display the number of rows I have. <?php //declare the SQL statement that will query the database $query = " SELECT COUNT(id) FROM connectvisits WHERE staffid = '$staffid' "; //execute the SQL query and return records $result = mssql_query($query); $thismonth = mssql_num_rows($result); echo "Total Meetings This Month: "; echo $thismonth; echo "<br />"; ?> For some reason I keep getting a result of 1. Everything else I try gives me a "Resource ID" number. Any help would be apprecaited. Maybe I have the completely wrong code. Thanks! hey i'm just woundering how i would go abouts on echoing unread messages sent to a user i want to beable to see how many unread messages i have Hello, I'm using the following code to count the amount of SQL results and divide it. Works great as is but I want to alter it so it works with categories. $amount = mysql_query('SELECT COUNT(`car_id`) AS num FROM `tbl_cars`') or die(mysql_error()); $amount_row = mysql_fetch_assoc($amount); I tried adding... WHERE car_cat = '".$cat."' which causes an error. Why doesn't this work, and how can I get the amount of results as a variable? returns -30. how can i remove the minus so it just returns 30 Code: [Select] $days = (strtotime(date("Y-m-d")) - strtotime($info['expiredate'])) / (60 * 60 * 24) echo $days Hello,
I am trying to get the report of my sales table. I want to get total number of leads for each month. And then i have to use this data to create graph using google graph.
But i am not getting how eactly i can get this.
Here is my code
<?php if(isset($_POST['submit'])) { $type = $_POST['type']; $sql="select * from leads where lead_customer='".$type."'"; $query=mysql_query($sql); while ($row = mysql_fetch_array($query)) { list($year,$month,$day)=explode("-", $row['last_modified']); $l = $row['last_modified']; $count=mysql_num_rows($month); echo $count; $myurl[] = "['".$month."', ".$count."]"; } print_r($myurl); echo implode(",", $myurl); } ?>But for $count, it doesn't show any values. below is my database. Capture.PNG 18.16KB 0 downloads Please suggest me How to write the code to get the count of the word "CHECKED" from a row? I tried this and it's not working. Please help. $query = mysql_query("SELECT field1, field2, field3, COUNT(CHECKED) as counter FROM db1 WHERE row_name = 'science'"); while($line = mysql_fetch_array($query)) { echo $query['counter']; } Hi guys, I want to count the number of rows in a table and want to display them. However that field stays empty. Everythign else works. What do I do wrong? Code: [Select] <?php //$sql="SELECT * FROM $tbl_name ORDER BY user_id"; $sql="SELECT * from sp_users,sp_schools where sp_users.user_id=sp_schools.school_id"; $result=mysql_query($sql); $num_rows=mysql_num_rows($result); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="779" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="777"> <div align="left"> <table width="779" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="6" align="center"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="25" align="center"><span class="style2">No.</span></td> <td width="62" align="center"><span class="style2">Name</span></td> <td width="104" align="center"><span class="style2">Lastname</span></td> <td width="130" align="center"><span class="style2">Email</span></td> <td width="342" align="center"><span class="style2">school</span></td> <td width="64" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['num_rows']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td><span class="style10"><? echo $rows['school_name']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> I am trying to echo the count for blog posts that have not been review yet, but I get this error. Notice: Undefined index: status but I feel like I have defined my status in my query. Plus my query is working as I have checked it in phpmyadmin Here is my function: Code: [Select] function unapproved_post_counter() { $sql = "SELECT COUNT(`approved`) AS `status` FROM `blog_posts` WHERE `approved` = 0 "; $result = mysql_query($sql); $data = array(); while (($row = mysql_fetch_assoc($result)) !== false) { $data[] = $row; } return $data; } Here is how I am echoing it. Code: [Select] $count = unapproved_post_counter(); <h1>Blog<span class="blogadds f_right"><?php echo $count['status']; ?> New Articles</span> print_r($count) tells me this... Array ( => Array ( [status] => 2 ) ) I need some help. I have this script that pulls timestamps from the database. What I want to do is create a count of how many of those timestamps that were returned were from the morning(6am-12pm), Afternoon (12pm-6pm), Evening (6pm-12am), or Night (12am-6am). How do I do I parse the timestamps to do that and display the count. Thanks! Code: [Select] <?php /** * @author William Morris * @copyright 2010 */ include('inc/db.php'); //function to show date and time based on timestamp function showTIME($timestamp){ $date = date('F j Y h:i:s A', $timestamp); return $date; } $startdate = "2010-07-01"; $enddate = "2010-08-05"; //query to pull time stamps in between dates //convert dates into timestamp //$startdate = strtotime($_POST['startdate']); //$enddate = strtotime($_POST['enddate']); //convert dates into morning timestamp $startdate1 = strtotime($startdate."06:00:00"); $enddate1 = strtotime($enddate."11:59:59"); $sql = mysqli_query($conn, "SELECT event_time FROM event WHERE event = 'Registration' AND event_time BETWEEN '$startdate1' AND '$enddate1'"); while($row = mysqli_fetch_array($sql)){ echo showTIME($row['event_time'])."<br>"; } ?> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306062.0 I have no idea why but no matter what the eventid is, the label always returns 20 and I"m not sure why. Is my synatx wrong? $eventid = (int)$_GET['eventid']; $result = mysqli_query($dbc, "SELECT count(label) FROM `events` WHERE `event_id` = '$eventid'"); $label = $result + 1; echo $label; |