MySQL query funkiness

    Date: 11/05/05 (PHP Community)    Keywords: mysql, sql

    I've always had trouble with mysql queries and using variables in them (such as, SELECT * FROM table WHERE id=$x). My current weirdness involves several queries--I have the main query. If certain pieces of information pulled from that query are not null, then it goes into a subquery and processes it. The code looks like this:

    while ($a_row = mysql_fetch_array($result)) {
    print "< img src=".$a_row['url']." border=0>< br />";
    print "< font size=\"-1\">".$a_row['blurb']."< br />";
    print "This photo was taken on .".$a_row['dateofpic'];
    if ($a_row['event'] != '') {
    $a_row['event'] = $picevent;
    $subquery1 = 'SELECT * FROM events WHERE id=$picevent';
    $subresult1 = mysql_query($subquery1) or die('Query failed: please try again ' . mysql_error());
    while ($suba_row = mysql_fetch_array($subresult1)) {
    print " during ".$suba_row['eventname'];
    }
    }

    I've bolded the query that's the problem. I've tried it where:

    $subquery 1 = 'SELECT * FROM events WHERE id=$a_row['event']';

    but that doesn't work--nothing shows up then. With the current query I have, it at least executes the above previous stuff before giving me an error. Any thoughts?

    Source: http://www.livejournal.com/community/php/364998.html

« The Mysterious Case of the... || Nested loops, functions... »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home