LegendFTW Posted February 15, 2011 Posted February 15, 2011 when converting some v1 files cause im practicing came into this error for car market Fatal error: Call to a member function query() on a non-object in /home/damagedc/public_html/carmarket.php on line 31 Also with the converting of v1 to v2 seems really easy to do but sometimes those arrays can get annoying cause sometimes you need them and sometimes you dont Quote
Kieran-R Posted February 15, 2011 Posted February 15, 2011 Post the code and then we will be able to help you ;) Quote
LegendFTW Posted February 15, 2011 Author Posted February 15, 2011 should be somewhere about here function cmarket_index() { global $ir,$c,$userid,$h; print " Viewing all listings... <table width=100% border=6> <tr style='background:black'> <th>Seller</th> <th>Car</th> <th>Acceleration Level</th> <th>Handling Level</th> <th>Speed Level</th> <th>Shield Level</th> <th>Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT cm.*, u.*,ct.* FROM carmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER LEFT JOIN cars_types ct ON ct.carID=cm.cmCAR ORDER BY cmPRICE ASC",$c); while($r=$db->fetch_rows($q)) { if($r['cmADDER'] == $userid) { $link = "[url='carmarket.php?action=remove&ID={$r[']Remove[/url]"; } else { $link = "[url='carmarket.php?action=buy&ID={$r[']Buy[/url]"; } print "\n<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['carNAME']}</td> <td>{$r['cmACC']}</td> <td>{$r['cmHAN']}</td> <td>{$r['cmSPD']}</td> <td>{$r['cmSHD']} <td>\$".number_format($r['cmPRICE'])."</td> <td>[$link]</td> </tr>"; } print "</table>"; } Quote
Equinox Posted February 15, 2011 Posted February 15, 2011 You need to declare the database variable within the function. function Test() { $db->query("SELECT blah FROM blah"); } becomes function Test() { global $db; $db->query("SELECT blah FROM blah"); } EDIT: You posted before me, so here: function cmarket_index() { global $ir,$c,$userid,$h, $db; print " Viewing all listings... <table width=100% border=6> <tr style='background:black'> <th>Seller</th> <th>Car</th> <th>Acceleration Level</th> <th>Handling Level</th> <th>Speed Level</th> <th>Shield Level</th> <th>Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT cm.*, u.*,ct.* FROM carmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER LEFT JOIN cars_types ct ON ct.carID=cm.cmCAR ORDER BY cmPRICE ASC",$c); while($r=$db->fetch_rows($q)) { if($r['cmADDER'] == $userid) { $link = "[url='carmarket.php?action=remove&ID={$r[']Remove[/url]"; } else { $link = "[url='carmarket.php?action=buy&ID={$r[']Buy[/url]"; } print "\n<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['carNAME']}</td> <td>{$r['cmACC']}</td> <td>{$r['cmHAN']}</td> <td>{$r['cmSPD']}</td> <td>{$r['cmSHD']} <td>\$".number_format($r['cmPRICE'])."</td> <td>[$link]</td> </tr>"; } print "</table>"; } Quote
Blade Maker Posted February 15, 2011 Posted February 15, 2011 Just copy his code and paste it where it shows that code in the file. All you need to do is add , $db in the globals call. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.