Jump to content

Mysql data retrieving


aznjay

Recommended Posts

I have many table from my database...my problem is showing the data from different table. Like switching table

 

for example:

TABLE1

id

title

date

article

 

TABLE2

id

title

date

article

 

First I used the code:

 

This page shows from mysql in links in PAGE1.php

include 'database.php';

$file = $_GET['page'];

$query  = "SELECT * FROM table1";

$result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result)){

 

echo '

<div id="tutorial"><a href="index.php?page='.$row['id'].'">'.$row['title'].'</a> </div>';

echo '<br>';

}

 

 

 

This shows the data from my mysql in links in PAGE2.php

include 'database.php';

$file = $_GET['page'];

$query  = "SELECT * FROM table2";

$result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result)){

 

echo '

<div id="tutorial"><a href="index.php?page='.$row['id'].'">'.$row['title'].'</a> </div>';

echo '<br>';

}

 

 

 

 

Whenever I click on a link the data shown with the code this is attached to index.php:

 

$query  = "SELECT * FROM table1 WHERE id= '$file'";

$result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result)){

 

echo $row['article'];

echo '<br>';

}

 

FROM table1 AND table2 HAVE SAME ID NUMBER, I WANT TO KNOW HOW TO  CHANGE FROM ONE TABLE TO ANOTHER, like SWITCH table1 who's ID is 1 to show from table2 who's ID is 1 USING LINKS

 

like:

index.php?table1=1

A SCRIPT THAT CAN DETECT WHICH TABLE IT NEEDS THROUGH THE LINK, AND SHOW DATA FROM THERE

index.php?table2=1

 

 

I NEED HELP PLEASE!!!

Link to comment
https://forums.phpfreaks.com/topic/123876-mysql-data-retrieving/
Share on other sites

ADDITIONAL DATA:

Undergoing website is alltraxx.uni.cc

This is in the context box of the page

 

<?php

$file = $_GET['page'].'.php';

if (file_exists($file)) {

include $file;

 

 

} elseif ($_GET['page'] == '') {

 

 

 

 

// how many rows to show per page

$rowsPerPage = 8;

 

// by default we show first page

$pageNum = 1;

 

// if $_GET['news'] defined, use it as page number

if(isset($_GET['news']))

{

$pageNum = $_GET['news'];

}

 

// counting the offset

$offset = ($pageNum - 1) * $rowsPerPage;

 

$idd = id ;

 

$query  = "SELECT * FROM news ORDER BY $idd DESC LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed');

$color="1";

// print the random numbers

while($row = mysql_fetch_array($result)){

 

if($color==1){

echo '

 

<div id="beam">

<span class="captive">'.$row['head'].'</span>

<span class="credit">'.$row['date'].'</span>

<span class="credit">'.$row['time'].' | </span>

<span class="credit">Author: '.$row['name'].' | </span>

<br>

<br><span class="txt">'.$row['msg'].'</span></div>';

 

 

// Set $color==2, for switching to other color

$color="2";

}

 

// When $color not equal 1, use this table row color

else {

echo '

<div id="beamer">

<span class="captive">'.$row['head'].'</span>

<span class="credit">'.$row['date'].'</span>

<span class="credit">'.$row['time'].' | </span>

<span class="credit">Author: '.$row['name'].' | </span>

<br>

<br><span class="txt">'.$row['msg'].'</span></div>';

// Set $color back to 1

$color="1";

}

}

 

echo '<br>';

 

// how many rows we have in database

$query  = "SELECT COUNT(id) AS numrows FROM news";

$result  = mysql_query($query) or die('Error, query failed');

$row    = mysql_fetch_array($result, MYSQL_ASSOC);

$numrows = $row['numrows'];

 

// how many pages we have when using paging?

$maxPage = ceil($numrows/$rowsPerPage);

 

// print the link to access each page

$self = $_SERVER['PHP_SELF'];

$nav = '';

for($page = 1; $page <= $maxPage; $page++)

{

if ($page == $pageNum)

{

$nav .= " $page ";  // no need to create a link to current page

}

else

{

$nav .= " <a class=\"links\" href=\"$self?news=$page\">$page</a> ";

}

}

 

// creating previous and next link

// plus the link to go straight to

// the first and last page

 

if ($pageNum > 1)

{

$page = $pageNum - 1;

$prev = " <a class=\"links\" href=\"$self?news=$page\">[Prev]</a> ";

 

$first = " <a class=\"links\" href=\"$self?news=1\">[First Page]</a> ";

}

else

{

$prev  = ' '; // we're on page one, don't print previous link

$first = ' '; // nor the first page link

}

 

if ($pageNum < $maxPage)

{

$page = $pageNum + 1;

$next = " <a class=\"links\" href=\"$self?news=$page\">[Next]</a> ";

 

$last = " <a class=\"links\" href=\"$self?news=$maxPage\">[Last Page]</a> ";

}

else

{

$next = ' '; // we're on the last page, don't print next link

$last = ' '; // nor the last page link

}

 

// print the navigation link

echo '<div align="center"><span class="mix">';

echo $first . $prev . $nav . $next . $last;

echo '</span>';

 

 

 

 

} else {

 

$query  = "SELECT * FROM phptut WHERE id= '$file'";

$result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result)){

 

echo $row['article'];

echo '<br>';

}

}

?>

</div>

</div>

</div>

</div>

 

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.