prudens Posted March 2, 2008 Share Posted March 2, 2008 OK, so I have something like //ID of Dogs 10002,20120,28844,49223 How do I separate them and put them into an array Dog[] ? Thanks! Link to comment https://forums.phpfreaks.com/topic/93965-array-help/ Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 <?php $id_of_dogs = '10002,20120,28844,49223'; $dog = explode(',',$id_of_dogs); // Split Them for($i=0;$i<count($dog);$i++){ echo $dog[$i] . '<br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-481435 Share on other sites More sharing options...
prudens Posted March 2, 2008 Author Share Posted March 2, 2008 thank u! Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-481442 Share on other sites More sharing options...
prudens Posted March 3, 2008 Author Share Posted March 3, 2008 $conn = mysql_connect ($sql_host,$sql_user,$sql_pass); $select = mysql_select_db ($sql_db,$conn); $query = "SELECT * FROM " . $sql_table_legislation . " WHERE id = $id"; $results = mysql_query ($query); $row = mysql_fetch_array($results); mysql_close($conn); // //$row should be LIKE "0219209,2923989,585783,..." $out = explode(',', $row); for ($i=0; $i<count($out); $i++) { echo $out[$i] . '<br>'; } The output is "Array".... for some reason... could you help please??? Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482179 Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 For echoing each value in the array try this instead: foreach($out as $value){ echo $value."<br />"; } Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482194 Share on other sites More sharing options...
prudens Posted March 3, 2008 Author Share Posted March 3, 2008 still doesn't work >< Still "Array" Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482201 Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 can you post back what this gives you: // right after this $out = explode(',', $row); // put print_r($out); Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482203 Share on other sites More sharing options...
prudens Posted March 3, 2008 Author Share Posted March 3, 2008 Array ( [0] => Array ) Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482216 Share on other sites More sharing options...
p2grace Posted March 3, 2008 Share Posted March 3, 2008 Try this instead: <?php conn = mysql_connect ($sql_host,$sql_user,$sql_pass); $select = mysql_select_db ($sql_db,$conn); $query = "SELECT * FROM " . $sql_table_legislation . " WHERE id = $id"; $results = mysql_query($query); if($results){ $arr = mysql_fetch_assoc($run); foreach($arr as $key => $value){ echo "$key = $value <br />"; } } ?> Let me know if that works. Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482217 Share on other sites More sharing options...
sasa Posted March 3, 2008 Share Posted March 3, 2008 change $out = explode(',', $row); to $out = explode(',', $row['put_name_of_database_field_with_dogs_ID_here']); Link to comment https://forums.phpfreaks.com/topic/93965-array-help/#findComment-482224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.