Hi,
I have a MySQL database with two tables. I need to be able to show a list of records from one table and one field from the other table like this
Table1Title1 Table1SubHeading1 Table2PageName Table1Desc1
Table1Title2 Table1SubHeading2 Table2OtherPageName Table1Desc2
Can someone point me in the right direction please
Regards
Bernard Davis
Selecting a particular record
Moderators: egami, macek, gesf
- Joan Garnet
- Moderator
- Posts: 387
- Joined: Sat Aug 03, 2002 2:56 am
- Location: Mars
- Contact:
Well,
there are other ways...
but I think this is faster -->
I hope It helped
bye!
there are other ways...
but I think this is faster -->
Code: Select all
<?php
$server = "localhost" ;
$login = "your_login" ;
$pass = "your_pass";
$table1 = "table1_name";
$table2 = "table2_name";
$data_base = "my_database_name";
$conection = mysql_connect($server,$login,$pass);
mysql_select_db($data_base,$conection);
////////////////////////////////////////////////////////
$sql_one = "select * from ".$table1." order by id desc";
$sql_two = "select * from ".$table2." order by id desc";
////////////////////////////////////////////////////////
$result_one=mysql_query($sql_one , $conection);
$result_two=mysql_query($sql_two , $conection);
////////////////////////////////////////////////////////
$i=0;
while ($row = mysql_fetch_array ($result_two)) {
for ($j=0; $j<mysql_num_rows($result_two); $j++){
$my_array[$j][$i] = $row[$j];
}
$i++;
}
print_r ($my_array);//you'll see the shape of this array, just comment this two lines when you see it clear
echo"<p>";
////////////////////////////////////////////////////////////////
/// This is the output. You can define it as you want ////
///////////////////////////////////////////////////////////////
while ($row = mysql_fetch_array ($result_one)) {
echo $row[0]." - ".$row[1]." - ".$my_array[0][1]." - ".$row[2]." - ".$row[3]." - "."<br>";
}
?>
I hope It helped
bye!
Hi,
Many thanks for your response, it almost does the trick. I can see how you are using an array to build the list of entries, but I still can't get it to work.
Perhaps if I ask a slightly different question -
How do I simply build an array which contains one field (say 'pageName' or field number 1) from every record in a table?
I know how to access the array once it is built, but I can't see how it is built in the first place.
Regards
Bernard Davis
Many thanks for your response, it almost does the trick. I can see how you are using an array to build the list of entries, but I still can't get it to work.
Perhaps if I ask a slightly different question -
How do I simply build an array which contains one field (say 'pageName' or field number 1) from every record in a table?
I know how to access the array once it is built, but I can't see how it is built in the first place.
Regards
Bernard Davis
- Joan Garnet
- Moderator
- Posts: 387
- Joined: Sat Aug 03, 2002 2:56 am
- Location: Mars
- Contact:
- Joan Garnet
- Moderator
- Posts: 387
- Joined: Sat Aug 03, 2002 2:56 am
- Location: Mars
- Contact:
ok,
I think this example will help you:
bye!
I think this example will help you:
Code: Select all
<?php
$my_string = " job , setup , office , supplies ";
$my_array = explode(",", $my_string);
for($i=0;$i<sizeof($my_array);$i++){
$no_white_spaces = trim($my_array[$i]);
echo $no_white_spaces."<br>";
}
?>
bye!