rmariano02 Posted May 10, 2012 Share Posted May 10, 2012 How can i call a specific row when ever a like. example : $record = mysql_query("select * from table_name"); ($getValue= mysql_fetch_row($record) //i'm not sure what should i use. should i use mysql_fetch_array, mysql_ fetch_ assoc, mysql_ fetch_ object, mysql_ field_ name and etc. print $getValue[$column_name][0]; 0 = value 1st row in the database/table_name 1 = value 2nd row in the database/table_name 2 = value 3rd row in the database/table_name ...... .... ...... ..... etc. is there a code i can do except from using sql_fetch_array then loop and put in into a multidimensional array? Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/ Share on other sites More sharing options...
xyph Posted May 10, 2012 Share Posted May 10, 2012 You'd have to use MySQLi <?php $sql = new MySQLi('localhost','root','pass','db'); $query = 'SELECT * FROM table'; $result = $sql->query($query); if( $result == FALSE ) echo 'There was a query error'; else $data = $result->fetch_all(MYSQLI_ASSOC); print_r($data); ?> Or code the loop yourself <?php mysql_connect('localhost','root',''); mysql_select_db('db'); $query = 'SELECT * FROM table_a'; $result = mysql_query($query); if( $result == FALSE ) echo 'Query error'; else { $data = array(); while( $row = mysql_fetch_assoc($result) ) $data[] = $row; } print_r($data); ?> Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344474 Share on other sites More sharing options...
rmariano02 Posted May 10, 2012 Author Share Posted May 10, 2012 Can i still use the same code in SQL to SQLi? or i still need to declare both SQL and SQLi? Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344502 Share on other sites More sharing options...
xyph Posted May 10, 2012 Share Posted May 10, 2012 Those snippets will work independent of each other. If you use the MySQLi version, I see no reason to keep the rest of your application on the old, unmaintained MySQL functions. Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344511 Share on other sites More sharing options...
rmariano02 Posted May 10, 2012 Author Share Posted May 10, 2012 Sorry i'm just new in PHP and SQL can i know what do you mean by Those snippets will work independent of each other. If you use the MySQLi version, I see no reason to keep the rest of your application on the old, unmaintained MySQL functions. sorry i'm not good in understanding English. do you mean is that i can no logger use the calling of sql in to SQLi? or i can still use the same code because SQLi can adopt to SQL old codes. i'm realy sorry for your trouble . Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344512 Share on other sites More sharing options...
xyph Posted May 10, 2012 Share Posted May 10, 2012 No, MySQLi knows nothing about the old MySQL resources or functions. I've provided you with a solution that works in both sets of functions. I'd strongly suggest moving your entire script over to MySQLi, as the old MySQL functions are no longer actively developed. That said, your application will still work fine if you stick with the old. If you don't want to change, the second snippet will do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344515 Share on other sites More sharing options...
rmariano02 Posted May 10, 2012 Author Share Posted May 10, 2012 Thank you so much again and sorry for asking too much questions. Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344528 Share on other sites More sharing options...
xyph Posted May 10, 2012 Share Posted May 10, 2012 Never too many questions. As long as you are ready to learn, we're here to help PHP keeps a lot of old functions that have been replaced or deemed 'bad practise' to avoid breaking existing, old scripts. This can make life VERY confusing for a new PHP developer, especially because a LOT of tutorials are never updated to reflect these changes. Quote Link to comment https://forums.phpfreaks.com/topic/262351-calling-a-specific-row-in-sql-when-ever-i-like/#findComment-1344531 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.