
nikster
Members-
Posts
11 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
nikster's Achievements

Newbie (1/5)
0
Reputation
-
Thanks Barand. Like I said, In MySQL, it's sorting fine. it's when I try and look at it via PHP. Nick
-
The date for Andres Segovia now looks right (February 21, 1893) but as I've progressed to the next phase of the project, I've come across a new but related issue. In the last issue, I was sorting by name. The next page groups all the Guitarists' birthdays by Month so now I'm sorting by birthday. Because, the (I think) PHP is interpreting 1983-02-21 as Jan 1 1970, even though it looks right (February 21, 1893 due to the formatting solution), the entry is showing up in the January group. Not the February group. Here's my query; $sql = mysql_query("SELECT * FROM guitaristbday ORDER BY MONTH(bday), bday ASC "); The date are in the MySQL database as 1893-02-21 in a field called bday and it's fromatted as type DATE. Again, I'm a nube so I don't manage the DB via a command line. I use PHPMyAdmin. WHen I click on the field name, it sorts it correctly. In ASC order, it puts that date first. When you do that, it puts the query of what you just did at the top of the page. SELECT * FROM `guitaristbday` ORDER BY `guitaristbday`.`bday` DESC LIMIT 0 , 30 Because I'm not exactly sure where the limitation is (MySQL or PHP) I'm not sure what side to tackle this from. Here is my PHP Code; ========================= <?php echo "<div align='left'>"; // Get format for formatted BDay month include "/includes/months.php"; // login to db include ("includes/db.php"); //Perform Query for Header info $sql = mysql_query("SELECT * FROM guitaristbday ORDER BY MONTH(bday), bday ASC "); //Show # of Records found echo "Total records found - " .mysql_num_rows ($sql).""; // initialize header and set it to an empty string $header = ''; // mysql_fetch_assoc will return each row from the result set while ($row=mysql_fetch_assoc($sql)) { $id = $row['id']; $name = $row['name']; $bday = $row['bday']; $bday2 = explode('-',$row['bday']); $bdayf = $months [$bday2[1]] .' ' . $bday2[2] .', ' . $bday2[0] ; $month_no = date('m', strtotime ($bdayf)); $month = date('F', strtotime ($bday)); // we only want to print the header if it hasn't been seen in the result yet if ($header!=$month) { echo "<div class='Titles'></br>"; echo "$month"; echo "</div></b>"; // means the current header display is for the nonth name $header = $month; } // include formatted City/Firm echo "$name - $bday<br/>"; } //close align div echo "<div>"; ?> ============================= Nick
-
There is clearly many ways to skin this cat. (I hope none of you have cats :-) They all work! Thank you all very much.
-
I'm running; PHP Version 5.3.10 MySQL Version 5.5.20 Again. I'm abit of a nube. I looked at that link. It's not completely clear on how to formulate the Query. Here's what my query currently looks like. (My goal is that if today is a guitarist's birthday it will show up in a side bar.) =================== $TodayM = (date ('m')); $TodayD = (date ('d')); $result = mysql_query(" SELECT * FROM guitaristbday WHERE MONTH(bday) = $TodayM AND DAY(bday) = $TodayD ORDER BY bday"); ====================
-
I have a database of guitarists birthdays. The birthday is stored in a MySQL DB in DATE format as YYYY-MM-DD. Virtuoso Spanish classical guitarist Andrés Segovia was born on Feb 21, 1893. I would like the PHP output to be "February 21, 1893". When I use the common date output. this date come out as January 1, 1970. I understand there is a problem with either the DB or PHP understanding dates pre 1900. (I'm a bit of a nube) Through a Google search I am able to get close with this code; while($row = mysql_fetch_array($result)) { $bday = explode('-',$row['bday']); $bdayf = $bday[1] .'/' . $bday[2] .'/' . $bday[0] ; echo "$bdayf"; } This outputs 02/21/1893. But I can't get it the final mile and get it to output as February 21, 1893. I have to beilive this a common problem but I cannot find a clear answer. I thank anyone in advance for your help. Nick Paonessa
-
THAT'S IT!! My mistake was I had to declare the $subtotal var BEFORE the while($row = mysql_fetch_array($result) Thank you so much MMDE.
-
I fairly new to PHP. This seems very obvious but I cannot find an answer. O programmer friend of mine said that I should never store a calculated value in a table because it was redundant. SO I have a very simple shopping cart. In the confirmation email, I ask the database for the line items of the order. So I'm pulling the quantity and price from the database. In the email I created a var called $ext which is $price * $disc which works. I cannot figure out how to total $ext. I created a var called $subtotal. Heres the code. $result = mysql_query("SELECT * FROM order_detail, products WHERE $ordid = orderid AND order_detail.productid = products.serial"); while($row = mysql_fetch_array($result)) { $prodid = $row['productid']; $qty = $row['quantity']; $price = $row['price']; $prodname = $row['name']; $proddesc = $row['description']; $ext = $qty * $price; $subtotal = 0; $subtotal = ($subtotal + $ext); } Any help would be appreciated.
-
That did it AyKay47! Thank you so much. I've learned more in the past few hours than I have in the past week. I can't wait to get good enough to help other guys like me. Thanks again. Here's the final working code in case this come up for anyone else and attached is a screen grab of the output. // query db $result = mysql_query(" SELECT estimates.loc_id, locations.loc_name, COUNT(*) FROM estimates LEFT JOIN locations ON estimates.loc_id = locations.loc_id WHERE estimates.date BETWEEN '$reportdatefrom' AND '$reportdateto' GROUP BY estimates.loc_id;") or die ('Error: '.mysql_error()); // output while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='center' width='200'>". $row['loc_name']. "</td>"; echo "<td align='center' width='200'>". $row['COUNT(*)']. "</td>"; echo "</tr>"; [attachment deleted by admin]
-
Thanks again AyKay47. I tried so many permutations of JOIN today, I'm pretty sure I tried the one you gave me. But it didn't work and I tried other things. I got the same error I was just getting; Error: Column 'loc_id' in field list is ambiguous But now I see that this is what I'm looking for, so I read some more from the link you posted and tried a few different things and got past that error. Now, the column I'm trying to get the name of the franchise to come up in is just blank. The numbers column is correct. I'm not getting any errors, but I cannot get the company name, or any data from either table to come up there weather I use the "locations." prefix or not. The only way any data will come up in that cell is if I use $row['loc_id']. Here's what the code looks like now; (A screen grab is also attached of the output.) // query db $result = mysql_query(" SELECT loc_id, COUNT(*) FROM estimates LEFT JOIN locations ON estimates.loc_id = locations.loc_id WHERE date BETWEEN '$reportdatefrom' AND '$reportdateto' GROUP BY loc_id;") or die ('Error: '.mysql_error()); // output while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='center' width='200'>". $row['locations.loc_name']. "</td>"; echo "<td align='center' width='200'>". $row['COUNT(*)']. "</td>"; echo "</tr>"; [attachment deleted by admin]
-
Thanks for your quick reply AyKay47. I did look at JOIN. Because there are different methods of JOIN (INNER, LEFT, RIGHT) and so many variables, I tried for hours and couldn't figure it out. I'm not sure which JOIN to use and where it goes in the query. If it's not too much trouble, can you give me an example or point me in then right direction?
-
Hi Everyone, I'm a noob to PHP although I have made great progress in the last few weeks. But now I'm stumped on what seems to be something simple. This project is a web app where customers enter in their info to ask for a free estimate to get their car body fixed which generates a lead. Because it's a franchise, at the end of the month, the owner counts the estimate requests (the leads) and bills the franchisees for each lead. (I know.. nice work if you can get it. :-) So I have a table called 'estimates' that stores all the lead info and the location ID of the franchise the lead is for (loc_id). In another table called 'locations' I have all the individual franchisee's info including their location ID (loc_id). So to get a count of the leads for the month I have the following query; // perform query $result = mysql_query(" SELECT loc_id, COUNT(*) FROM estimates WHERE date BETWEEN '$reportdatefrom' AND '$reportdateto' GROUP BY loc_id;") or die ('Error: '.mysql_error()); // output results while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='center' width='200'>" . $row['loc_id'] . "</td>"; echo "<td align='center' width='200'>" . $row['COUNT(*)'] . "</td>"; echo "</tr>"; .. which gives me the result I want, but not formatted how I want. I'd like to be able to show (using the estimates.loc_id & locations.loc_id relationship) the Franchise's name instead of just their their ID (loc_id) which is stored in the 'locations' table. I feel a bit stupid because it's like I was able to bake the cake, which is supposed to be the hard part, but now I can't seem to put on the icing, which is supposed to be the easy part. Any help would be greatly appreciated.