Jump to content

Content on the same page of the query


jofftan

Recommended Posts

Hi, I'm looking for a way to choose data content from a dropdown menu, linked to a MySQL DB, and echo it on that same page.
The problem is when you get to that page for the first time I need to display the first entry of the data by default.

Now I have it but with two php files, I want this on the same page.

The way it is right now is

Page 1 ;
[code]
<?php

$c = mysql_connect ($host,$usager,$Mpasse);
mysql_select_db ('db', $c);

if (!$c) {
  die('Impossible de se connecter : ' .  error_reporting(E_ALL));
}
 
$req = "SELECT * FROM Team";
$resultat = mysql_query($req);

echo '<ul id="subnavlist">';
 
while ($record = mysql_fetch_assoc($resultat)) {

echo '<li id="subactive"><a href="corpoTeam.php?id_team='.$record["id_team"].'" id="current">'.$record["Titre"].'</a></li>';

}
    echo "</li>";
?>
[/code]

Page 2;
[code]
<?php

$_POST['id_team'];
    include 'connexion.php';

$c = mysql_connect ($host,$usager,$Mpasse);
mysql_select_db ('db', $c);

if (!$c) {
  die('Impossible de se connecter : ' . mysql_error());
}
 
$req = "SELECT * FROM Team";
$resultat = mysql_query($req);

echo '<ul id="subnavlist">';
 
while ($record = mysql_fetch_assoc($resultat)) {

echo '<li id="subactive"><a href="corpoTeam.php?id_team='.$record["id_team"].'" id="current">'.$record["Titre"].'</a></li>';

}
    echo "</li>";
?>
</li>
</ul>

</div>
<div>
<?php
          ini_set('display_errors', 1);
error_reporting(E_ALL);

            $req = "SELECT * FROM Team WHERE id_team = ".$id_team;
//                        $resultat = mysql_query ("SELECT Titre, description, name FROM Team WHERE id_team = '".urldecode($_GET['id_team'])."'");
                    $resultat = mysql_query($req);
                    $row=mysql_fetch_array($resultat);


                    $name = $row['name'];
                    $Titre = $row['Titre'];
                    $description = nl2br($row['description']);
                   
                    echo "<br>";
                    echo "<br>";             
                    echo '<h4>';
                    echo $name;
                    echo '<br>';
                    echo $Titre;
                    echo '</h4>';
                    echo '<p>';
                    echo $description;
                    echo '</p>';
                   
?>
[/code]

Thank you
Link to comment
Share on other sites

Here's the link
[url=http://www.virochempharma.com/corpo.php]http://www.virochempharma.com/corpo.php[/url]

When you get to this page I'm echoing the first entry of the DB.
If you select another entry from the dropdown it call a second page.

I want all that operation on a single page.

I don't know if it's possible ?
Link to comment
Share on other sites

Yea, I understand what you are saying now... instead of these links on the left changing the page  (corpo_mission.php, corpo_history.php, etc...) you want to only change the text.

This cannot all be done with PHP.  You will need to change the hyperlinks to call a javscript function that changes the text in that box.  However, within this Javascript function you create, you will need to use PHP to pull the data from the DB.

I cannot help you easily with the javascript aspect... I would post this in the Javascript help forum.
Link to comment
Share on other sites

if you are asking to have a dropdown populated by entries in your db, and info changing on your page, like say, info in another dropdown, when you select a different dropdown value, before you have to go and click submit, then you are going to need a javascript method called AJAX. 

go to ajaxfreaks.com or google it.
Link to comment
Share on other sites

Not exactly.

Ok now it's calling the same page within the link so it work I don't know if it's secure but it work.

[code] while ($record = mysql_fetch_assoc($resultat)) {

echo '<li id="subactive"><a href="corpo.php?id_team='.$record["id_team"].'" id="current">'.$record["Titre"].'</a></li>';

}[/code]

But now I got this error to fix

[quote]Notice: Undefined variable: id_team in /var/www/vhosts/virochempharma.com/httpdocs/corpo.php on line 106

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/virochempharma.com/httpdocs/corpo.php on line 109[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.