prince198 Posted June 9, 2009 Share Posted June 9, 2009 hi i have problem in some function php i have 2 tbale from databse first table is items seconds is items2 i have 2 function the first is dispalying 8 items from my first table function item(); $sql ="select from table1"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $item = $row[item]; $href = $row['href']; $value = $row['value']; <a href='$href"=>{$item} name='$value' </a> } } so i have resulut home|tutorials|scripts----- until now is working but i want to create other function for items linked to my second table fo exemple if i click on tutorial i have to display items2 from second table that have same id of first table however i don't find solution to use $value from first function on second function it's undefined on error page thanks for help Link to comment https://forums.phpfreaks.com/topic/161553-function-with-php-and-mysql/ Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 how about something like this; $sql = "SELECT * FROM `table1`, `table2` WHERE `table1`.`id`=`table2`.`id`"; Link to comment https://forums.phpfreaks.com/topic/161553-function-with-php-and-mysql/#findComment-852518 Share on other sites More sharing options...
prince198 Posted June 9, 2009 Author Share Posted June 9, 2009 thanks for answer the problem i use template with many div in first div i have to display first items in left on website i have to display seconds items .tha's why i need to have 2 functions i have website example but in french may be u want the adress to unterstand more my prob Link to comment https://forums.phpfreaks.com/topic/161553-function-with-php-and-mysql/#findComment-852521 Share on other sites More sharing options...
gevans Posted June 9, 2009 Share Posted June 9, 2009 I can't do too much without seeing some more code. But it sounds like you just need to store your results from both tables in a multi-dimensional array and itterate over them appropriately. Link to comment https://forums.phpfreaks.com/topic/161553-function-with-php-and-mysql/#findComment-852528 Share on other sites More sharing options...
prince198 Posted June 9, 2009 Author Share Posted June 9, 2009 hi again and thanks i will write most important part of my script and i hope i untestand first class.php [code]public function items($linked = false, $page=false) { $sql = array( 'SELECT' => '*', 'FROM' => items ); $sql=$this->build_key_query($sql); // Retrieving the last sql // Getting the result form the last SQL while($row = mysql_fetch_assoc($result)) { $item= $row['item]; $href = $row['href']; $value = $row['value]; // Generating the main portion of the data table $page .= <a href='$href' value=$value>$item </a> } return $page; [/code] for $page i use smarty tamplate to diplay resuly items(true, false,$items);//$items for smarty template so until now i have my items but now in other div i want to display the items related top the table 1 when i click on href [code][code][table] [tr] [td]like i explained in the top i tried this second function $sql = array( 'SELECT' => '*', 'FROM' => "items2", 'JOIN' => "liens_gauches_princp", 'ON' => 'liens_items1.id = items2.id', where => value=$value[/td] [/tr] [/table] [/code][/code] but of course $value of function1 is undefined for script in that case i hope that u unterstand me sorry if i made mistake but here i writ without seeing on input there is bugs when i write here Link to comment https://forums.phpfreaks.com/topic/161553-function-with-php-and-mysql/#findComment-852546 Share on other sites More sharing options...
prince198 Posted June 9, 2009 Author Share Posted June 9, 2009 no bodu untersantd my problem? ??? Link to comment https://forums.phpfreaks.com/topic/161553-function-with-php-and-mysql/#findComment-852567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.