Jump to content

function with php and mysql


prince198

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.