Jump to content

Archived

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

jofftan

Content on the same page of the query

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

Share this post


Link to post
Share on other sites
It sounds like to me you are talking about implementing Javascript... but your question is not quite to clear.  COuld explain in clearer terms what you want...

Thanks

Share this post


Link to post
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 ?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
No I'm sorry I wasn't clear enough.
The links are in the dropdown of team members in the middle of the page.

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.