Jump to content

kellerkind

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kellerkind's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Found a solution: SELECT word FROM words WHERE id NOT IN ( SELECT id FROM users WHERE user = 'Steve' ) ORDER BY RAND() LIMIT 1 But this still works with ORDER BY RAND and I can't find a way to use the alternative posted in the sticky here in this forum. Any ideas?
  2. Hi, I have to query the db in the following scenario. I develop a little vocabulary learning application and have two tables. One with users and ids of words that they already know. The other table has all words in the db. I'm looking for a way to get a random word from the table WORDS for steve that is not one of the words he already knows. TABLE USERS user | id steve | 12 steve | 14 steve | 10 lara | 10 TABLE WORDS word | id fun | 7 hard | 12 cool | 10 strong | 15 It would be fantastic if anyone could help me with this one. Right now I first get all the words that Steve already knows and build a query ($protect). Then I use this query to get the random word. "SELECT * FROM vocdb WHERE item = 'Vocabulary' AND status = 'Approved' $protect ORDER BY RAND() LIMIT 1"
  3. Hi, this problem drove me nuts for a couple of hours. A mysql query got executed several times even though it was in no loop or anything else that could have caused it. I pinned it down to one external php function and actually solved the problem while I made a function to show here. I just want to share this because it seems quiet uncommon. Would be nice to get some comments on it. Ok first i connect to mysql nothing special here mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("the_db") or die(mysql_error()); This here is the query that gets added three times to the table in my db. Nothing special as well. $addsize = "INSERT INTO `temp_cart` (`id` ,`sess_id` ,`item_name` ,`item_id` ,`item_info` ,`item_use`,`item_code`,`item_price`) VALUES (NULL, '2', '2', '2', '2', '2', '2', '2')"; $result = mysql_query($addsize) or die(mysql_error()); Here comes the evil php function that caused the problem and was the reason that all queries on this site got exectued twice. (I made it shorter that its easy to read) function stepimg($image, $title, $subheader, $extended = 0, $extra = 0) { echo '<table cellpadding="0" cellspacing="0" border="0" background="#222222" width="580"> <tr> <td width="125"> </td> <td width="455"> '.$title; echo '</td> </tr> </table>'; } stepimg("img/checkout.gif" ,"Checkout" , "Please enter your details", "Checkout"); This looked pretty good to me but the problem was: background="#222222" I never ever thought that this could cause a mysql query to execute several times. It's kinda funny as more often you add a table with background="#222222" as more often the query gets executed. I had it two times in this function so the mysql query got executed three times. Can anyone tell me why this happened? Does the page load more often or what?
  4. Hey cool thanks a lot! I did some weird stuff with 2dimensional arrays and have a couple of querries now but at least it works but I give union a try. Muchas gracias!
  5. Hi, I'm new to join statements and it would be great if anyone could help me. I did some tutorials but I'm not sure if i can do what i want to do with join. [u]PROBLEM[/u] I have a variable number of tables called "newsposts" (newsposts1, newsposts2, newsposts3...) In each of these tables I have a column with "postdate". I want to get the 10 latest entries from all "newsposts" tables. [u]SOLUTION?[/u] So my idea was to first create an array with all names of "newsposts" tables and after that Join all these tables and use order by "postdate" with a limit of 10 to display the latest data from all "newsposts" tables. [u]QUESTION[/u] Could it work like this and do you have an example of how such a join statement would look like? Thanks a lot, Jay
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.