-
Posts
3,372 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Muddy_Funster
-
Loop within loop/query within query best practices
Muddy_Funster replied to msaz87's topic in MySQL Help
I have had to use a SELECT within a SELECT only when doing a comparison filter between MySQL and Microsoft SQL Server. As for the UPDATE loop you posted - you have a bit of a missunderstanding about how that would work. -
Deffinately my quote of the week!
-
hmm, give this a shot then: $start = $_POST['start_date']; $end = $_POST['finish_date']; $sql = "SELECT order_id, order_num, date, SUM(nett_price) as total, (SUM(nett_price) / DATEDIFF('$end', '$start')) AS daily_avg FROM orders WHERE ((complete = 'Y') AND (tx_type ='PAYMENT') AND (date BETWEEN '$start' AND '$end'))"; also update youre or die() to read: or die("ERROR: >> <BR>".mysql_error()."<BR> this occured trying to run the following query: <BR> $sql");
-
Basic OOP question: using classes in multiple files
Muddy_Funster replied to kn0wl3dg3's topic in PHP Coding Help
no problem. -
sounds likely, append or die ("ERROR: >> ".mysql_error()); to both the lines with mysql_query() and mysql_fetch_assoc() (taking out the ; that is already there) and we will get an ide of where it's all going wrong.
-
no problem at all, glad I could help
-
Basic OOP question: using classes in multiple files
Muddy_Funster replied to kn0wl3dg3's topic in PHP Coding Help
there is a method for classes where by you can basicly tell php that "if this class isn't loaded already, check this file for it - if it's there load it " have a look at http://php.net/manual/en/language.oop5.autoload.php -
Genius! see, if I knew what I was dooing I wouldn't look quite as stupid as I feel! That was exactly the issue and now the script is working. On to figure out how to populate the div now. Thanks again PFMaBiSmAd
-
Just thought I would ask as I see that the AJAX help board is something of a ghost town (much like the MS SQL board). Since my post there doas also have some php in it, and I am in no way certain my problem is not in the php could anyone that knows a bit of both please have a look at it here: http://www.phpfreaks.com/forums/index.php?topic=343419.0 cheers, just hope this circumvents the double posting rule
-
Posting (NULL) into a field from a form...
Muddy_Funster replied to Jim R's topic in PHP Coding Help
ahhh, so if I want to inject some code on your site I'll just not use a name field, got it -
Basic OOP question: using classes in multiple files
Muddy_Funster replied to kn0wl3dg3's topic in PHP Coding Help
I'm still not clear, are you trying to access a class over multiple pages or are you simply looking to make a value available to multiple pages? -
try changing: $db_orders_query_result = mysql_query($sql, $db_connection); print($db_orders_query_result['daily_avg']); to: $db_orders_query = mysql_query($sql, $db_connection); $db_orders_query_result = mysql_fetch_assoc($db_orders_query); print_r ($db_orders_query_result);
-
Posting (NULL) into a field from a form...
Muddy_Funster replied to Jim R's topic in PHP Coding Help
that's all great untill someone puts in white space or a control character. incidently, why are you only running some inputs through mysql_real_escape_string() and not all of them? -
well if it's just a display problem and not an actual grouping issue, conditionalise the display $filter = ''; foreach($array as $key => $value){ if ($filter != $value){ echo " ".$value."<br />"; $filter = $value; } }
-
Basic OOP question: using classes in multiple files
Muddy_Funster replied to kn0wl3dg3's topic in PHP Coding Help
There are different ways of doing different things depending on what the object actualy is. How about being a little more specific on what you are looking for? -
Posting (NULL) into a field from a form...
Muddy_Funster replied to Jim R's topic in PHP Coding Help
you could just change your SELECT statement to use WHERE (comments IS NULL AND comments != '') -
could you elaborate on "doesn't work"?
-
by group together do you meen display each one only once?
-
howas about keeping it all together?: $sql = 'SELECT order_id, order_num, date, SUM(nett_price) as total, COUNT(DISTINCT date) as num_days, (ROUND(SUM(nett_price) / COUNT(DISTINCT date)), 2) AS daily_avg '; $sql .= 'FROM orders '; $sql .= 'WHERE complete = "Y" AND tx_type = "PAYMENT" AND date >= "'.$_POST['start_date'].'" AND date <= "'.$_POST['finish_date'].'" ';
-
OK, I have some code for you, going by what I think you are looking for. Have a look over it and replace your current while loop with the following if you think it suits: $query = "SELECT id, thumbpath, fullpath, tag, desc, adddate FROM portfolio ORDER BY adddate ASC"; $tagCheck = 'nonsenese value'; //anything that is never going to be an actual tag value $fistCheck = true; // variable to check if the output is the first because if it's not we will need to close the div before opening another one $result = mysql_query ($query); //you could realy use some error capture on your query stuff While($row = mysql_fetch_array($result)) // loop through the results from the query { if($tagCheck != $row['tag']) //check if the tag value from the database is different to what the last value was { //if it is different then if($firstCheck != true) //check if this is NOT the first record returned { //if this is not the first record returned then echo "</div>"; // close the last div }else //if this is the first record { $firstCheck = false; //update variable to show that first record has now been returned } $tagCheck = $row['tag']; // still if the tag value is different - update tag value to be the same echo "<div class='boxgrid'>"; // as this is a new tag we need a new div } // the following information will be processed every time $fPath = $row['fullPath']; $tPath = $row['thumbPath']; $desc = $row['desc']; echo "<a href=\"$fpath\" rel=\"prettyPhoto['$tagCheck']\"><img src=\"$tPath\" title=\"$desc\"/></a>"; } //end of recordset return loop echo "</div>" //now we are done close off the last div It's not tested, so will odds on have a few errors in it. Let me knopw what you think.
-
do you want to do it in php or sql?
-
you could just use SELECT AVG(nett_value)....
-
lets see your table structure then
-
what are you planning to use to identify when a new div should be apllied?