-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
"Range" is a MySQL reserved word. Date is permitted.
-
Ask for advice Ignore it Pay someone else to do it That's a great approach to learning you have there!
-
Forget my last post, and Ch0cUr's for that matter (numeric values should not be quoted) I just noticed your date field is a timstamp so it will automatically set to the current time on insert. No need to include it in your query mysqli_query($con,"INSERT INTO battery ( Range, Percent, Sleep) VALUES ($miles, $battery_level, 1)"); (However, when using date values they should be quoted)
-
the date variable needs to be in single quotes ( a string value) ... VALUES ('$date', $miles, $battery_level, 1)
-
I found the ADLDAP class invaluable when dealing with AD http://adldap.sourceforge.net/
-
SELECT name , SUM(gp) as played , SUM(goals) as goals , SUM(assists)as assists , SUM(pts) as points , SUM(pim) as pim FROM stats GROUP BY name
-
Having Trouble Passing Values From HTML page to PHP page
Barand replied to 2l8vsan's topic in PHP Coding Help
$user = $_POST['username']; $pass = $_POST['password']; echo $user; ?> <p>Hello <?php echo $user; ?></p> <p>Goodbye <?php echo ("$password"); ?></p> As you can see from the highlighting, you store in $pass then echo $password. However, $user should echo. Also, there should be no whitespace before the opening <?php tag otherwise session_start() will fail. -
The query you are running is not the same as the one I suggested Mine $get = "SELECT * FROM ".TBL." WHERE test = '1' AND '{$fieldx['ShortVersion']}' IN (test, test2, test3, test4)"; Yours $getu = "SELECT * FROM ".TBL_USERS." WHERE confirmed = '1' AND '{".$fieldx['ShortVersion']."}' IN (test1, test2, test3, test4)"; If you echo my version you get SELECT * FROM TBL WHERE confirmed = '1' AND 'TST' IN (test1, test2, test3, test4) If you echo your version you get SELECT * FROM TBL_USERS WHERE confirmed = '1' AND '{TST}' IN (test1, test2, test3, test4) This because {..} has special significance when embedding variables in a double-quoted string. See http://www.php.net/manual/en/language.types.string.php EG $var = 'World'; echo "Hello $var!"; //--> Hello World! echo "Hello {$var}!"; //--> Hello World! echo "Hello {".$var."}!"; //--> Hello {World}! - your version equivalent
-
So now you know why it isn't working. '{TST}' != 'TST'
-
The value you are searching for contains the curly braces ie "{TST}". Do any of your db table columns contain that value?
-
The usual way is to display the name but pass the unique id in the link, so echo "<li><a href='userpage.php?id={$user['id']}'>{$user['name']}</a></li>";
-
you need the earlier time first with a BETWEEN SELECT `username` FROM `navigate` WHERE `time` BETWEEN NOW() - INTERVAL 5 MINUTE AND NOW()
-
$getu = "SELECT * FROM ".TBL_USERS." WHERE confirmed = '1' AND '{."$fieldx['ShortVersion']."}' IN (test1, test2, test3, test4)"; echo $getu; Post the output, it is not going to give that error message
-
What do you get if you echo $getu;
-
how to select last value for a particular value both in the same table
Barand replied to udaystrad's topic in MySQL Help
It's bit of both. Usually the solution is known but if I have the time I prefer to test out my proposed solution to make sure I haven't made any stupid typos (like forgetting to remove a comma from a query). Other times I know roughly how to tackle it but a bit of experimentation with test data and a visit to the manual is required, especially if it requires something I haven't used before. -
I hadn't heard of that sample database so I just downloaded it. Although the schema is comprehensive, the data in it leaves a lot to be desired. Doing an analysis by language mysql> SELECT l.name as language, COUNT(f.film_id) as films -> FROM language l -> LEFT JOIN sakila.film f USING (language_id) -> GROUP BY l.name; +----------+-------+ | language | films | +----------+-------+ | English | 1000 | | French | 0 | | German | 0 | | Italian | 0 | | Japanese | 0 | | Mandarin | 0 | +----------+-------+ 6 rows in set (0.01 sec) and by category mysql> SELECT c.name as category, l.name as language, COUNT(f.film_id) as films -> FROM -> category c -> INNER JOIN film_category fc USING (category_id) -> INNER JOIN film f USING (film_id) -> INNER JOIN language l USING (language_id) -> GROUP BY c.name,l.name; +-------------+----------+-------+ | category | language | films | +-------------+----------+-------+ | Action | English | 64 | | Animation | English | 66 | | Children | English | 60 | | Classics | English | 57 | | Comedy | English | 58 | | Documentary | English | 68 | | Drama | English | 62 | | Family | English | 69 | | Foreign | English | 73 | | Games | English | 61 | | Horror | English | 56 | | Music | English | 51 | | New | English | 63 | | Sci-Fi | English | 61 | | Sports | English | 74 | | Travel | English | 57 | +-------------+----------+-------+ 16 rows in set (0.01 sec) and although there is a many-to-many relationship between film and category there is not a single film in more than one category mysql> SELECT f.title, COUNT(c.category_id) as numCats, -> GROUP_CONCAT(c.name SEPARATOR ', ') as Categories -> FROM film f -> INNER JOIN film_category fc USING (film_id) -> INNER JOIN category c USING (category_id) -> GROUP BY f.film_id -> HAVING numCats > 1; Empty set (0.01 sec)
-
to be precise, my code gives <option value='1'>1</option>
-
Variables inside double quotes are translated into their values, so <select name="day"> <option value="">Day</option> <?php for($day=1;$day<=31;$day++){ echo "<option value='$day'>$day</option>"; } ?> </select> <select name="month"> <option value="">Month</option> <?php $months=array(1=>Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec); for($counter=1;$counter<=12;$counter++){ echo "<option value='$counter'>{$months[$counter]}</option>"; } ?> </select>
-
}else{ $find_multiple=" SELECT password FROM resgistration WHERE username='$username' "; $result = mysql_query($find_multiple ) or die (mysql_error()); $query=mysql_fetch_assoc($result); if (mysql_num_rows($result)==1) { if($password==$query['password']){ $_SESSION['login']=$username; echo " successsfully login!".$_SESSION['login']; }else{ echo "Invalid info"; } } else { echo "Invalid info"; } }
-
you only select username so there is no password in the row. This is pretty useless exercise $find_multiple=" SELECT username FROM resgistration WHERE username='$username' "; You only need to select the password, you already know the username
-
you need to call session_start() at top of every page using $_SESSION. It must be called before any output is sent to the browser including HTML output.
-
I assume the <div>s have a float:left style. Try $datatb = 'datatb'; $sql = "SELECT s.sub_cat_id, s.sub_cat_name, t.id, t.topic_title FROM ( SELECT sub_cat_id, sub_cat_name FROM subcategory ORDER BY sub_cat_id DESC LIMIT 5 ) as s INNER JOIN $datatb t ON (s.sub_cat_id=t.sub_id) ORDER BY s.sub_cat_id DESC , t.id DESC"; $res = mysql_query($sql); $prev = ''; while ($row = mysql_fetch_assoc($res)) { if ($prev != $row['sub_cat_id']) { // has sub_cat changed? echo "{$row['sub_cat_name']}<br>"; $prev = $row['sub_cat_id']; } echo "<div class='topic_list' id='topic_list{$row['id']}'> <a href='review.php?topic_id={$row['id']}&datatb=$datatb'>"; echo strtoupper($row['topic_title']); echo "</a></div>"; }
-
Throw away my query - it won't work for what you are trying to do. What does "$datatb" contain in your links where you have "&datatb=$datatb"?
-
... which is exactly what the query and my code gives you. Now you introduce the need for links. When you get people's time for free, don't tell them you want one thing, then, when they have done it, tell them you wanted something different. It wastes their time. Good luck.