SELECT * FROM video WHERE vid={$item_arr[$i]['id']} Code (markup): So in the same document I have this - <?=$item_arr[$i]['id']?> - it works perfectly fine when it's not in a php query But that string above is in php, so how do I convert this ={$item_arr[$i]['id']} into a MYSQL PHP query? Thanks in advance
First: both of those statements are in PHP - the second one does not contain a MySQL query, the first one does. try as follows: SELECT * FROM video WHERE vid='$item_arr[$i][id]'
$vid = $item_arr[$i][id]; SELECT * FROM video WHERE vid='$vid' should work . cheat way to do it though. the syntax you need for the statement to work as is: SELECT * FROM video WHERE vid='".$item_arr[$i][id]."' I believe is correct. It should at the least put you on the right path.
I don't know your complete script but why don't you put it in variable and then call fetch. $data = mysql_query("SELECT * FROM video WHERE vid=$item_arr[$i]['id']") ; $result = mysql_fetch_array($data); & than echo your results. use print_r($result) for list of arrays.
not really, odds are you didn't copy it over exactly. which is why I avoid using the second syntax. if it didn't work with reassignment to a variable. did you echo out the variable to see what value it held? after that will be put the SQL into a string and echo it out until you eliminate any possible error.
To see what problem , do that: $sql = "SELECT * FROM video WHERE vid=$item_arr[$i]['id']" ; echo $sql; $data = mysql_query($sql) ; $result = mysql_fetch_array($data); PHP: and see what it echo's into screen, tell us what it echo's and what your are waiting.
Well, this is strange. None of the strings that are previously mentioned in the same document seem to work via echo
Hmm... I think that somewhere in your code, you are either nullifying or unsetting the table. Putting echo $item_arr[$i]['id']; PHP: does show the proper value?
<?switch($vars[1]){case'id':?> <div class="menuLightHeader"> <div class="l"><?=$text['addBy']?>: <a href="/user/<?=$item_arr['varr'][0]['uid']?>"><?=$item_arr['varr'][0]['username']?></a></div> <div class="r"><?if((isLogined) && ($_SESSION['user']['id'] == $item_arr['varr'][0]['uid'])){?><a href="/video/del/<?=$item_arr['varr'][0]['id']?>" onClick="if(!confirm('<?=$text['sure']?>?')) return false;"><?=$text['delete']?></a><?}?></div> <div class="clear"></div> </div> <div id="padder"> <table class="simpleTable" width="100%" cellspacing="0" cellpadding="0"> <tr class="selected"> <td><a href="<?=(($additional_arr['links']['global']['prev'] > 0) ? '/video/id/'.$additional_arr['links']['global']['prev'] : '#')?>">« <?=$text['prev']?></a></td> <td align="center"><div class="menuHeader" style="text-align: center;"><?=$boxNames['video']?> » » <?=$text['all']?></div></td> <td align="right"><a href="<?=(($additional_arr['links']['global']['next'] > 0) ? '/video/id/'.$additional_arr['links']['global']['next'] : '#')?>"><?=$text['next']?> »</a></td> </tr> </table> <center> <p id="player"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p> <script type="text/javascript"> var s2 = new SWFObject("/flvplayer.swf","single","500","400","7"); s2.addParam("allowfullscreen","false"); s2.addVariable("file","/=/<?=$item_arr['varr'][0]['filename']?>.flv"); s2.addVariable('linkfromdisplay','true'); s2.addVariable("displayheight","400"); s2.addVariable("backcolor","0x000000"); s2.addVariable("frontcolor","0xCCCCCC"); s2.addVariable("lightcolor","0x557722"); s2.addVariable("autostart","true"); s2.addVariable("width","500"); s2.addVariable("height","400"); s2.write("player"); </script> </center> <?if(($additional_arr['links']['user']['next'] > 0) || ($additional_arr['links']['user']['prev'] > 0)){?> <table class="simpleTable" width="100%" cellspacing="0" cellpadding="0"> <tr class="selected"> <td><a href="<?=(($additional_arr['links']['user']['prev'] > 0) ? '/video/id/'.$additional_arr['links']['user']['prev'] : '#')?>">« <?=$text['prev']?></a></td> <td align="center"><div class="menuHeader" style="text-align: center;"><?=$boxNames['video']?> » » <?=$item_arr['varr'][0]['username']?></div></td> <td align="right"><a href="<?=(($additional_arr['links']['user']['next'] > 0) ? '/video/id/'.$additional_arr['links']['user']['next'] : '#')?>"><?=$text['next']?> »</a></td> </tr> </table> <?}?> </div> echo $item_arr[$i]['id']; <?php // Create a connection to your database. // Query database and select the last 10 entries. $data = mysql_query("SELECT * FROM (SELECT a.username, a.id, b.vid, b.timestamp, b.text, b.uid FROM users a INNER JOIN video_comments b WHERE a.id = b.uid) AS ttbl WHERE vid='.$id.' ORDER by timestamp ASC"); while($row = mysql_fetch_array($data)) { echo" <div class='menuLightHeader'> <div class='l'>: <a href=/user/".$row[id].">".$row[username]."</a></div> <div class='clear'></div> </div> <div class='menuComment'> ".$row[text]." </div> </div> "; } ?> Code (markup): Here's the full code, but doesn't include the module itself. Any thoughts?
Your syntax at mysql query is wrong + $id is empty. 1. vid='.$id.' should be vid='$id' or vid=".$id." - because don't forget your mysql_query("") uses double quotes , not single quote 2. $id is empty. You should add this line before the query: $id = $item_arr[$i]['id']; This should work. I never look at other part except the sql part. <?switch($vars[1]){case'id':?> <div class="menuLightHeader"> <div class="l"><?=$text['addBy']?>: <a href="/user/<?=$item_arr['varr'][0]['uid']?>"><?=$item_arr['varr'][0]['username']?></a></div> <div class="r"><?if((isLogined) && ($_SESSION['user']['id'] == $item_arr['varr'][0]['uid'])){?><a href="/video/del/<?=$item_arr['varr'][0]['id']?>" onClick="if(!confirm('<?=$text['sure']?>?')) return false;"><?=$text['delete']?></a><?}?></div> <div class="clear"></div> </div> <div id="padder"> <table class="simpleTable" width="100%" cellspacing="0" cellpadding="0"> <tr class="selected"> <td><a href="<?=(($additional_arr['links']['global']['prev'] > 0) ? '/video/id/'.$additional_arr['links']['global']['prev'] : '#')?>">« <?=$text['prev']?></a></td> <td align="center"><div class="menuHeader" style="text-align: center;"><?=$boxNames['video']?> » » <?=$text['all']?></div></td> <td align="right"><a href="<?=(($additional_arr['links']['global']['next'] > 0) ? '/video/id/'.$additional_arr['links']['global']['next'] : '#')?>"><?=$text['next']?> »</a></td> </tr> </table> <center> <p id="player"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p> <script type="text/javascript"> var s2 = new SWFObject("/flvplayer.swf","single","500","400","7"); s2.addParam("allowfullscreen","false"); s2.addVariable("file","/=/<?=$item_arr['varr'][0]['filename']?>.flv"); s2.addVariable('linkfromdisplay','true'); s2.addVariable("displayheight","400"); s2.addVariable("backcolor","0x000000"); s2.addVariable("frontcolor","0xCCCCCC"); s2.addVariable("lightcolor","0x557722"); s2.addVariable("autostart","true"); s2.addVariable("width","500"); s2.addVariable("height","400"); s2.write("player"); </script> </center> <?if(($additional_arr['links']['user']['next'] > 0) || ($additional_arr['links']['user']['prev'] > 0)){?> <table class="simpleTable" width="100%" cellspacing="0" cellpadding="0"> <tr class="selected"> <td><a href="<?=(($additional_arr['links']['user']['prev'] > 0) ? '/video/id/'.$additional_arr['links']['user']['prev'] : '#')?>">« <?=$text['prev']?></a></td> <td align="center"><div class="menuHeader" style="text-align: center;"><?=$boxNames['video']?> » » <?=$item_arr['varr'][0]['username']?></div></td> <td align="right"><a href="<?=(($additional_arr['links']['user']['next'] > 0) ? '/video/id/'.$additional_arr['links']['user']['next'] : '#')?>"><?=$text['next']?> »</a></td> </tr> </table> <?}?> </div> echo $item_arr[$i]['id']; <?php // Create a connection to your database. $id = $item_arr[$i]['id']; // Query database and select the last 10 entries. $data = mysql_query("SELECT * FROM (SELECT a.username, a.id, b.vid, b.timestamp, b.text, b.uid FROM users a INNER JOIN video_comments b WHERE a.id = b.uid) AS ttbl WHERE vid='$id' ORDER by timestamp ASC"); while($row = mysql_fetch_array($data)) { echo" <div class='menuLightHeader'> <div class='l'>: <a href=/user/".$row[id].">".$row[username]."</a></div> <div class='clear'></div> </div> <div class='menuComment'> ".$row[text]." </div> </div> "; } ?> PHP:
You're welcomed. Always check if the variable has been assigned a value either by 1. Search using your text/php editor 2. echo()ing its value Good luck. - ads2help