weeder Posted November 14, 2008 Share Posted November 14, 2008 using mccodes I trying to add a country flag to another page depending on which country they are in. Here is where i am so far $ct= mysql_fetch_object(mysql_query("SELECT coun_flag FROM countries WHERE coun_id = '{$ct['country']}'")); echo "<center><img src='{$ir['coun_flag']}' width='50' height='50'><br /><br /> and get a error off this line echo "<center><img src='{$ir['coun_flag']}' width='50' height='50'><br /><br /> can anyone help many thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/ Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 What is the error you get? There's no closing quote and semicolon at the end of this line. Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/#findComment-690295 Share on other sites More sharing options...
weeder Posted November 14, 2008 Author Share Posted November 14, 2008 This the error Fatal error: Cannot use object of type stdClass as array in Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/#findComment-690327 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 And it explains a lot First you use mysql_fetch_object to get data from database loaded into object $ct Then you try to use it as an array... makes no sense To access data in object use: (where is $ir defined by the way? it's not in the code you posted) $ir->coun_flag Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/#findComment-690333 Share on other sites More sharing options...
weeder Posted November 14, 2008 Author Share Posted November 14, 2008 ok users can go to different countries The datatable table is countries and there is a image url stored in coun_flag. The table that stores which country the user is in is the users database in column country. I am trying to get the image of which country they are in to show on a sidemenu. I think i have the mysql_fetch_object right but its the array thats got me. But being new on php I have tried all i can think of and now lost, I hope this helps, can't think of another way to explain Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/#findComment-690343 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 Maybe you didn't notice Use: $ir->coun_flag instead of $ir['coun_flag'] Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/#findComment-690356 Share on other sites More sharing options...
weeder Posted November 14, 2008 Author Share Posted November 14, 2008 Sloved $ct = mysql_query("SELECT `coun_flag` FROM `countries` WHERE `coun_id` = '{$ir['country']}'") or die (mysql_error()); $ct = mysql_fetch_object($ct); echo '<center><img src="' . $ct->coun_flag . '" width="50" height="50"></center><br />'; Thanks a lot for your help Quote Link to comment https://forums.phpfreaks.com/topic/132735-solved-a-little-help-with-sql/#findComment-690366 Share on other sites More sharing options...
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.