Hrvoje Posted November 21, 2010 Share Posted November 21, 2010 I need to select all fields from two tables and echo that data. Fields are the same in both tables but has different data. <?PHP include "dbconnect.php"; function pretvoriDatum($mysqlDatum) { $tmp=explode("-", $mysqlDatum); $datum=$tmp[2] . "." . $tmp[1] . "." . $tmp[0]; return $datum; } $sql="SELECT * FROM novosti A, dogadanja B"; if (!$q=mysql_query($sql)) { echo "Error" . mysql_query(); die(); } if (mysql_num_rows($q)==0) { echo "No data</div>"; } else { ?> <?PHP while ($redak=mysql_fetch_array($q)) { ?> <?php echo $redak["a.naslov"]; ?> <?PHP echo $redak["a.slika"]; ?> <?php echo $redak["b.tekst"]; ?> <?php echo $redak["a.objavio"]; ?> <?PHP echo pretvoriDatum($redak["b.datum"])?> <?PHP } } ?> Please help, I don't know how to do that Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/ Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 it looks like you're doing it. is there an error or a problem?? Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137543 Share on other sites More sharing options...
Hrvoje Posted November 21, 2010 Author Share Posted November 21, 2010 When I echo <?php echo $redak["a.naslov"]; ?> Error is: Notice: Undefined index: a.naslov Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137551 Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 that means there is no such thing as $redak["a.naslov"] i would take a closer look at $redak: print_r($redak); Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137556 Share on other sites More sharing options...
Hrvoje Posted November 21, 2010 Author Share Posted November 21, 2010 I don't understand this :-\ Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137570 Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 update your code to look like this, so you will see what is in $redak while ($redak=mysql_fetch_array($q)) { print_r($redak); Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137584 Share on other sites More sharing options...
Hrvoje Posted November 21, 2010 Author Share Posted November 21, 2010 Now i have all data in one table Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137595 Share on other sites More sharing options...
sasa Posted November 21, 2010 Share Posted November 21, 2010 'a.naslov' is not same as 'A.naslov' you use alias A Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137599 Share on other sites More sharing options...
Hrvoje Posted November 21, 2010 Author Share Posted November 21, 2010 Ok, thanks... But when I put: <?PHP include "dbconnect.php"; function pretvoriDatum($mysqlDatum) { $tmp=explode("-", $mysqlDatum); $datum=$tmp[2] . "." . $tmp[1] . "." . $tmp[0]; return $datum; } $sql="SELECT * FROM novosti A, dogadanja B"; if (!$q=mysql_query($sql)) { echo "Error" . mysql_query(); die(); } if (mysql_num_rows($q)==0) { echo "No data</div>"; } else { ?> <?PHP while ($redak=mysql_fetch_array($q)) { ?> <?php echo $redak["A.naslov"]; ?> <?PHP } } ?> Again have an error Undefined index: A.naslov Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137625 Share on other sites More sharing options...
BlueSkyIS Posted November 21, 2010 Share Posted November 21, 2010 if you print_r($redak) as suggested, you'll see the contents of $redak, including the available keys/field names. Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137647 Share on other sites More sharing options...
Hrvoje Posted November 21, 2010 Author Share Posted November 21, 2010 Thanks everyone, I figured now You make my day Quote Link to comment https://forums.phpfreaks.com/topic/219378-mysql-select/#findComment-1137668 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.