-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
Can php do two execute (queries) in same time?
Barand replied to sigmahokies's topic in PHP Coding Help
try something like this <?php include('db_inc.php'); // defines HOST etc $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $sql = "SELECT firstname , lastname , local FROM member ORDER BY firstname, lastname"; $local = ''; $nonlocal = ''; $res = $db->query($sql); while (list($fn, $ln, $loc) = $res->fetch_row()) { if ($loc=='Y') { $local .= "$fn $ln<br>"; } else { $nonlocal .= "$fn $ln<br>"; } } ?> <html> <head> </head> <body> <table border='1'> <tr><th>Local</th><th>Non-Local</th></tr> <tr style='vertical-align: top;'> <td><?=$local?></td> <td><?=$nonlocal?></td> </tr> </table> </body> </html> -
Yes, it will. For the THIRD time (and last), do not put those variable inside single quotes. $stmt->bindValue(':fname', $_POST["fname"]); If you totally disregard the advice given, why bother posting at all and waste our time.
-
You are still repeating the same mistake. Read and learn. Also you should check that the values were posted before using. You almost had this check but commented out the code. That check should have enclosed the query too otherwise you check if they exist but then go ahead and use them anyway.
-
You are missing the word "WHERE" in the query
-
Can php do two execute (queries) in same time?
Barand replied to sigmahokies's topic in PHP Coding Help
SNAP! -
Can php do two execute (queries) in same time?
Barand replied to sigmahokies's topic in PHP Coding Help
There is a multi query option but I have never found the need to use it. In you example I cannot see a need either. If you want to separate the local and non-local you can ORDER BY local. If, as it appears, you are only interested in how many of each SELECT local, COUNT(*) as total FROM members GROUP BY local; -
Dispaying one random image whenever page refreshed
Barand replied to morrism35's topic in PHP Coding Help
Make the directory separator / instead of \ -
Dispaying one random image whenever page refreshed
Barand replied to morrism35's topic in PHP Coding Help
The string you are echoing is in single quotes therefore the variable is not expanded. Use double quotes echo "<img src='\$template[0]' >"; -
In other words, never miss out on an opportunity to expose your database structure to the world at large
-
In that statement you are setting the :fname parameter to the literal string $-f-n-a-m-e and not the contents of the variable $fname. That is because of the single quotes around the variable. Variables inside double-quotes are expanded to their values but those inside single-quotes are not. Lose the quotes around the variables. Should be $stmt->bindValue(':fname', $fname);
-
The INSERT appears to do nothing because that is exactly what it is doing. You have to execute the query.
-
Finding all files with "download" and "jpg, png, gif"
Barand replied to morrism35's topic in PHP Coding Help
$imagefiles = glob("images/download*.{png,jpg,gif}", GLOB_BRACE); echo '<pre>',print_r($imagefiles, true),'</pre>'; -
Every post I make says it in my sig
-
did you add this line and rerun the code? if ($records==false) echo mysql_error();
-
$sql="SELECT * FROM APARTMENTS"; $records=mysql_query($sql); if ($records==false) echo mysql_error(); See what the error message tells you.
-
Then your query failed and mysql_query is returning "false" echo mysql_error() after calling mysql_query() to see why
-
Finding all files with "download" and "jpg, png, gif"
Barand replied to morrism35's topic in PHP Coding Help
Take a look at the glob function -
try this SELECT sc.StringyChat_name , sc.StringyChat_ip , sc.StringyChat_time FROM StringyChat sc INNER JOIN ( SELECT StringyChat_name , MAX(StringyChat_time) as StringyChat_time FROM StringyChat GROUP BY StringyChat_name ) latest USING (StringyChat_name, StringyChat_time) WHERE sc.StringyChat_time >= (UNIX_TIMESTAMP() - 3600) AND StringyChat_name NOT IN ( '" . implode($galleries, "', '") . "' ) ORDER BY StringyChat_time DESC LIMIT $offset, $rowsperpage If that gets what you want then you need to JOIN to user2 to get the id's in the same query. (Don't run queries inside loops)
-
Because you use SELECT * there is no way I can know what you really want from the table. You could SELECT name, MAX(date) FROM table GROUP BY name but, as I said, I don't know what else you want
-
When you GROUP BY (in this case) name you get ONE row for each name. If a particular name has 100 records with different times it can only display the time from one of the records. The manuals states the choice will be arbitrary but it usually takes the first value from the group - hence the oldest.
-
And as you are using a prepared statement anyway, you should be using a placeholder and binding the parameter value. That's the reason for prepared statements.
-
You need quotes around string values WHERE username = '{$_GET['username']}'
-
Sorry, I didn't realize that was teaching, it sure confused me.
-
try this to correct the dates in the table UPDATE date_sample SET date = CASE WHEN dayofweek(date)=1 THEN date + INTERVAL 1 DAY -- change Sun to Mon WHEN dayofweek(date)=7 THEN date - INTERVAL 1 DAY -- change Sat to Fri ELSE date -- leave weekdays alone END If you want to leave them alone in the table but modify on selection then you can use the same CASE statement SELECT CASE WHEN dayofweek(date)=1 THEN date + INTERVAL 1 DAY -- change Sun to Mon WHEN dayofweek(date)=7 THEN date - INTERVAL 1 DAY -- change Sat to Fri ELSE date -- leave weekdays alone END as date FROM table
-
You could ... ORDER BY date='$XXX' DESC LIMIT 1