Maq
Administrators-
Posts
9,363 -
Joined
-
Last visited
-
Days Won
3
Everything posted by Maq
-
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
You don't absolutely need it. It's just an alias to reference the column easier for brevity purposes. I see. Kind of like storing it in a variable instead of having to type SUM['$var'] just like when you store $var = $_GET['name'] You could think of it that way -
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
You don't absolutely need it. It's just an alias to reference the column easier for brevity purposes. -
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
Missing the AS total: $query2 = "SELECT SUM($type2) AS total FROM customers WHERE sched=1"; -
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
Change these lines to (I think your $row line wasn't correct): $query2 = "SELECT SUM($type2) AS total FROM customers WHERE sched=1"; and echo "Total ". " = $". $row['total']; -
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
Are you sure you have values in your db WHERE sched=1? The only time SUM returns null is when the result set is empty. -
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
Take out the periods: $query2 = "SELECT SUM('$type2') as total FROM customers WHERE sched=1"; $type2 will interpolate because the primary string is in double quotes. -
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
Echo $query2 out and see exactly what the query is. -
You're assigning here NOT comparing: if ($cartype = 1 ) Besides, you have elseif statements, only one block will get executed.
-
Using Variables in MYSQL Query not working. Help please!
Maq replied to madjack87's topic in PHP Coding Help
Where is $type2 defined? -
just checked this thread for the first time today..wondering how cars and gloves are involved...lol I think you answered your own question.
-
roseman5544, DO NOT double post, I delete your other thread. Also don't mark as urgent, please look at the rules: http://www.phpfreaks.com/page/rules-and-terms-of-service
-
- First of all, your code does not populate a form field as far as I can see. Does your print statement output anything? - You should be sanitizing any input to the database with mysql_real_escape_query to prevent sql injections. - You have an extra terminating '}' here, but no starting one (fatal error): // Show data print($row[plunum]); } - Your query looks valid, although I can't guarantee that it's correct. If you are seeing a blank screen it's because you have the fatal error I mentioned above. Fix it and put these 2 lines directly under your opening <?php tag to detect further errors: ini_set ("display_errors", "1"); error_reporting(E_ALL);
-
You don't need that huge array, you can simply use rand. I revamped your code a bit: ini_set ("display_errors", "1"); error_reporting(E_ALL); class Game { function __construct() { //Constructor } function display($max) { $results = null; $i = 0; while($i { $results[] = rand(1,$max); echo " "; $i++; } print_r($results); return $results; } } $max = 35; $object1 = new Game(); $object1->display($max); ?>
-
The date functions are a bit slow but for only displaying 7 days of the week and the benefit of having the flexibility of changing/adding to the format, I think it's worth it.
-
AFAIK, it doesn't matter. Why, do they act differently in your code?
-
In the future you can temporarily use or die(mysql_error()) to display mysql errors. But you should eventually fix/handle them properly.
-
Comments in the code (check out date for date formatting, the "l"): //Gets the current day (Thursday) $cDay = strtotime(date("d")); //Loop through 1-7, to increment each day of the week for($i=1; $i{ //"l" is just the format for date (A full textual representation of the day of the week) //strtotime takes the current day ($cDay) and adds +1 ($i) each loop, adding a day echo '' . date("l", strtotime('+'.$i.'day', $cDay)) . ' $i -> +' . $i . 'day '; } ?> Output: Thursday $i-> +1day Friday $i-> +2day Saturday $i-> +3day Sunday $i-> +4day Monday $i-> +5day Tuesday $i-> +6day Wednesday $i-> +7day Hope that makes sense.
-
FYI, in your first code, which I don't really get, you would change the last bit to (comments in the code): $zmienna=mysql_fetch_array($result2); //need to fetch the result2, not query2 if($zmienna){echo " Command z is successful ";} else {echo " Command z is not successful ";} echo " Result: ".$zmienna['value2']; //need to use zmienna, because it holds the result set (array data), not query2 which is just a string
-
Crashes it or shows a blank page? It works for me (ff3). Output (of course I don't have your CSS class): If it's blank, try turning on error reporting: ini_set ("display_errors", "1"); error_reporting(E_ALL);
-
Try something like: $cDay = strtotime(date("d")); for($i=1; $i{ echo '' . date("l", strtotime('+'.$i.'day', $cDay)) . ''; } ?>
-
date and strtotime are probably what you're going to need here. Do you have any code for us to work off of?
-
Sure. AJAX is an easy concept to grasp but sometimes a pain to implement. If you have more questions, don't hesitate.
-
Yes, how else would your program know the BD to use? mysql_query is what actually executes your query. Read the documentation...
-
CSV fields are a horrible idea, don't do that. You need to use the IN() function.
-
Read the documentation: http://www.apachefriends.org/en/xampp-windows.html