JeditL
-
Posts
10 -
Joined
-
Last visited
Never
Posts posted by JeditL
-
-
Hi
I got an array like this:
$array[$i][$j]=array('first'=>'one','second'=>'two','third'=>null);
and I would like to add value to the field third later in a loop. I came up with this idea:
$x=0; for($i=0;$i<$numrows;$i++) { for($j=0;$j<$numfields;$j++) { foreach($array[$i][$j] as $field) { $x++; if($x==3) { $row='three'; $x=0; } } } }
But sure there must be easier way, right? The length of my code for the simple looking task feels just ridiculously long and complicated . I hope you can help to fix it.
Thanks in advance.
-
Hi
I'm using MySQL Workbench to get visible structure of my database. I can get all the tables but not the relations between the tables. Is it possible to get an image from database with relations? If not with Workbench maybe with some other program?
Thanks in advance.
-
Hello
I got two-dimensional array that contains multiple arrays:
$array[$i][$j]=array('first'=>$row['name'],'second'=>$row['address']);
I'm using while($row=mysql_fetch_array($result)) to get data to the array. That works fine but after I try to loop the array using foreach I get only first letters. Here is my code:
for($i=0;$i<$num;$i++) { for($j=0;$j<$rows;$j++) { foreach($array[$i][$j] as $row) { echo $row['name']; } } }
Can I use foreach to loop the array so that I get whole strings and not just first letters? If not can I do it with some other method?
Thanks in advance.
-
Use mysql_query("SET NAMES UTF8"); when conneting to your database.
Thanks, mate. That did the trick. All the letters are now shown correctly. Cheers!
-
Hi, I can't get PHP to display letters ä and ö that are brought from database correctly. It's fine if I just echo the letters but getting letters to show correctly from database is causing problems.
$str = utf8_decode($str);
works fine with PHP strings but not with strings from MySQL. Please help. I really should get this to work.
Thanks in advance.
-
Hi, thanks for the reply. What I'm trying to solve here is:
What if I had multidimensional array like this:
$array['row1'][0]=0;
$array['row1'][1]=1;
$array['row1'][2]=2;
$array['row2'][0]=3;
$array['row2'][1]=4;
$array['row2'][2]=5;
and I would like to use foreach to display every field of the array. How do I do that using foreach?
-
Hello
I got 2 mysql queries in my code. I need them both because the second one needs a value from the first one that the query succeeds. I would like to print the data from both of the queries at the same time.
$query1="SELECT...";
$query2="SELECT...";
$result1=mysql_query($query1);
$result2=mysql_query($query2);
while ($row = mysql_fetch_array($result1) { //how to add both of the results here?
echo $row['name'];
echo $row['color'];
}
How to fetch from both of the result arrays in same while loop? Is it even possible?
Thanks again to everyone replying.
-
I solved my problem. It was mysql associative array so your method didn't work on that. My bad, I didn't tell about that cause I thought it wouldn't matter but it did. I used this:
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
echo $row['name'];
I would still like to know how to display the data of $result array with foreach() if it is even possible. Is it?
-
Hi, I'm still a newbie to PHP and I got a simple problem that I just can't get solved.
I got an associative array and I would like to use (for example print) only particular fields of the array.
For example my array has fields "name", "address" etc. and it holds many names and addresses. I would like to echo all the names from the array but nothing else.
I've tried:
foreach ($array as $field)
echo $field['name'];
and I've tried aswell:
foreach ($array['name'] as $field
echo $field;
but they just won't work. Please help me. I know this is simple problem and I hope you can help me easily. Thanks to anyone replying.
[SOLVED] How to add values to an array that is inside of other array?
in PHP Coding Help
Posted
Thanks for the reply.
After googling for a while I found out how push_array() works and it didn't seem to be possible to add associative key to the field pushed but instead I found this solution:
Link: http://www.phpro.org/examples/Array-Push-Assoc.html
Eh.. Simple solution . Problem solved!