Jump to content

database help


martin9t9

Recommended Posts

hey guys this is sorta hard to explain so ill give it a go anyways, just bare with me.

 

on my site im retrieving data from a database and what i wanna do is retrieve data from another database but have it in the other database

 

here's the code of what ive got:

<?php
require_once('auth.php');
?>
<?php $id = $_SESSION['SESS_MEMBER_ID'] ?>
<html>
<head>
<title>Announcement</title>
</head>
<body>

<table border="0" width="100%" height="100%">

<tr height="15%">
<td colspan="5"><?php include "header.php"; ?></td>
</tr>

<tr> 

<td>

<table border="0" width="100%" height="100%">

<tr>
<td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td>
<td width="50%" valign="top"><center>
<center><div class="subheading"><b>All Networks</b></div></center>

<?php

$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name 
$tbl_name="post"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="100%">

<tr>
<td rowspan="2" width="45" height="45"> </td>
<td colspan="2"><a href="view-profile.php?uid=<?php echo $rows['uid'] ?>" class="postname"><? echo $rows['first']; ?> <? echo $rows['last']; ?></a> on <a class="postname"><? echo $rows['network']; ?></a></td>
</tr>
<?php $network = $rows['network']; $postid = $rows['id']; ?>
<tr>
<td><div class="post"><? echo $rows['post']; ?></div></td>
<td width="45"></td>
</tr>

<tr>
<td colspan="3" class="text" align="right"> 

<?php 
  if($rows['user'] !== $_SESSION['SESS_USER']) 
  echo '<a href="like-exec.php?postid=' . $rows['id'] . '&url=member-index.php"><img src="resources/tick.png" alt="Like" border="0"></img></a><font class="like"> ' . 
  


$host1="***"; // Host name 
$username1="***"; // Mysql username 
$password1="***"; // Mysql password 
$db_name1="***"; // Database name 
$tbl_name1="rating"; // Table name 

// Connect to server and select database.
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect server "); 
mysql_select_db("$db_name1")or die("cannot select DB");

$sql="SELECT SUM(yes) as total FROM $tbl_name1 WHERE postid='$postid'";
$result=mysql_query($sql);

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

echo $rows['total']; 

}
mysql_close(); //close database 
  
  
    '</font> - <a href="dislike-exec.php?postid=' . $rows['id'] . '&url=member-index.php&like=' . $rows['no'] . '"><img src="resources/cross.png" alt="Dislike" border="0"></img></a> <font class="dislike"> ' . $rows['no'] . '</font>'; 
  else 
  echo '<font class="like"> ' . $rows['yes'] . '</font> - <font class="dislike"> ' . $rows['no'] . '</font>'; 
?>

</td>

</tr>

</table>
<hr color="#F0F0F0">
<?
}
mysql_close(); //close database
?>


</center></td>
<td width="25%"></td>
</tr>

</table>

</td>

</tr>

</table>

</body>
</html>



please help with is bugging me so much!

 

Link to comment
Share on other sites

<?php
require_once('auth.php');
?>
<?php $id = $_SESSION['SESS_MEMBER_ID'] ?>
<html>
<head>
<title>Announcement</title>
</head>
<body>

<table border="0" width="100%" height="100%">

<tr height="15%">
<td colspan="5"><?php include "header.php"; ?></td>
</tr>

<tr> 

<td>

<table border="0" width="100%" height="100%">

<tr>
<td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td>
<td width="50%" valign="top"><center>
<center><div class="subheading"><b>All Networks</b></div></center>

<?php

$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name 
$tbl_name="post"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM database1.$tbl_name ORDER BY id DESC";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="100%">

<tr>
<td rowspan="2" width="45" height="45"> </td>
<td colspan="2"><a href="view-profile.php?uid=<?php echo $rows['uid'] ?>" class="postname"><? echo $rows['first']; ?> <? echo $rows['last']; ?></a> on <a class="postname"><? echo $rows['network']; ?></a></td>
</tr>
<?php $network = $rows['network']; $postid = $rows['id']; ?>
<tr>
<td><div class="post"><? echo $rows['post']; ?></div></td>
<td width="45"></td>
</tr>

<tr>
<td colspan="3" class="text" align="right"> 

<?php 
  if($rows['user'] !== $_SESSION['SESS_USER']) 
  echo '<a href="like-exec.php?postid=' . $rows['id'] . '&url=member-index.php"><img src="resources/tick.png" alt="Like" border="0"></img></a><font class="like"> ' . 
  




$sql2="SELECT SUM(yes) as total FROM database2.$tbl_name1 WHERE postid='$postid'";
$result2=mysql_query($sql2);

while($rows=mysql_fetch_array($result2)){

echo $rows2['total']; 

}
mysql_close(); //close database 
  
  
    '</font> - <a href="dislike-exec.php?postid=' . $rows2['id'] . '&url=member-index.php&like=' . $rows2['no'] . '"><img src="resources/cross.png" alt="Dislike" border="0"></img></a> <font class="dislike"> ' . $rows2['no'] . '</font>'; 
  else 
  echo '<font class="like"> ' . $rows['yes'] . '</font> - <font class="dislike"> ' . $rows2['no'] . '</font>'; 
?>

</td>

</tr>

</table>
<hr color="#F0F0F0">
<?
}
mysql_close(); //close database
?>


</center></td>
<td width="25%"></td>
</tr>

</table>

</td>

</tr>

</table>

</body>
</html>

 

dont forget to replace database1 and database2 with whatever your databases are called

Link to comment
Share on other sites

you had opened , and not closed a set of brackets, also you had an echo missing:

<?php
require_once('auth.php');
?>
<?php $id = $_SESSION['SESS_MEMBER_ID'] ?>
<html>
<head>
<title>Announcement</title>
</head>
<body>

<table border="0" width="100%" height="100%">

<tr height="15%">
<td colspan="5"><?php include "header.php"; ?></td>
</tr>

<tr> 

<td>

<table border="0" width="100%" height="100%">

<tr>
<td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td>
<td width="50%" valign="top"><center>
<center><div class="subheading"><b>All Networks</b></div></center>

<?php

$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name 
$tbl_name="post"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM database1.$tbl_name ORDER BY id DESC";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="100%">

<tr>
<td rowspan="2" width="45" height="45"> </td>
<td colspan="2"><a href="view-profile.php?uid=<?php echo $rows['uid'] ?>" class="postname"><? echo $rows['first']; ?> <? echo $rows['last']; ?></a> on <a class="postname"><? echo $rows['network']; ?></a></td>
</tr>
<?php $network = $rows['network']; $postid = $rows['id']; ?>
<tr>
<td><div class="post"><? echo $rows['post']; ?></div></td>
<td width="45"></td>
</tr>

<tr>
<td colspan="3" class="text" align="right"> 

<?php 
  if($rows['user'] !== $_SESSION['SESS_USER']) {
  echo '<a href="like-exec.php?postid=' . $rows['id'] . '&url=member-index.php"><img src="resources/tick.png" alt="Like" border="0"></img></a><font class="like"> ' . 
  

$sql2="SELECT SUM(yes) as total FROM database2.$tbl_name1 WHERE postid='$postid'";
$result2=mysql_query($sql2);

while($rows=mysql_fetch_array($result2)){

echo $rows['total']; 

}
mysql_close(); //close database 
  
   
echo   '</font> - <a href="dislike-exec.php?postid=' . $rows['id'] . '&url=member-index.php&like=' . $rows['no'] . '"><img src="resources/cross.png" alt="Dislike" border="0"></img></a> <font class="dislike"> ' . $rows['no'] . '</font>'; 
}    else {
  echo '<font class="like"> ' . $rows['yes'] . '</font> - <font class="dislike"> ' . $rows['no'] . '</font>'; 
?>

</td>

</tr>

</table>
<hr color="#F0F0F0">
<?
}}
mysql_close(); //close database
?>


</center></td>
<td width="25%"></td>
</tr>

</table>

</td>

</tr>

</table>

</body>
</html>

Link to comment
Share on other sites

sorry but it still didnt work... it showed my webpage but it had a heap of errors in it :

 

SELECT SUM(yes) as total FROM martin9t9.rating WHERE postid='105'

Warning: mysql_query() [function.mysql-query]: Can't connect to MySQL server on 'localhost' (10061) in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 67

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 67

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 69

 

Warning: mysql_close(): no MySQL-Link resource supplied in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 90

 

 

Warning: mysql_close(): no MySQL-Link resource supplied in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 74

Link to comment
Share on other sites

just to let you know it says it cant connect to the server on 'localhost' mines not local host its an IP address not sure if this helps.

<?php
require_once('auth.php');
?>
<?php $id = $_SESSION['SESS_MEMBER_ID'] ?>
<html>
<head>
<title>Announcement</title>
</head>
<body>

<table border="0" width="100%" height="100%">

<tr height="15%">
<td colspan="5"><?php include "header.php"; ?></td>
</tr>

<tr> 

<td>

<table border="0" width="100%" height="100%">

<tr>
<td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td>
<td width="50%" valign="top"><center>
<center><div class="subheading"><b>All Networks</b></div></center>

<?php

$host="1*2.*0.1*3.2*"; // Host name 
$username="martin9t9"; // Mysql username 
$password="***"; // Mysql password 
$db_name="martin9t9"; // Database name 
$tbl_name="post"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 

$sql="SELECT * FROM martin9t9.$tbl_name ORDER BY id DESC";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="100%">

<tr>
<td rowspan="2" width="45" height="45"> </td>
<td colspan="2"><a href="view-profile.php?uid=<?php echo $rows['uid'] ?>" class="postname"><? echo $rows['first']; ?> <? echo $rows['last']; ?></a> on <a class="postname"><? echo $rows['network']; ?></a></td>
</tr>
<?php $network = $rows['network']; $postid = $rows['id']; ?>
<tr>
<td><div class="post"><? echo $rows['post']; ?></div></td>
<td width="45"></td>
</tr>

<tr>
<td colspan="3" class="text" align="right"> 

<?php 
  if($rows['user'] !== $_SESSION['SESS_USER']) {
  echo '<a href="like-exec.php?postid=' . $rows['id'] . '&url=member-index.php"><img src="resources/tick.png" alt="Like" border="0"></img></a><font class="like"> ' . 
  

$sql2="SELECT SUM(yes) as total FROM martin9t9.rating WHERE postid='$postid'";
$result2=mysql_query($sql2);

while($rows=mysql_fetch_array($result2)){

echo $rows['total']; 

}
mysql_close(); //close database 
  
   
echo   '</font> - <a href="dislike-exec.php?postid=' . $rows['id'] . '&url=member-index.php&like=' . $rows['no'] . '"><img src="resources/cross.png" alt="Dislike" border="0"></img></a> <font class="dislike"> ' . $rows['no'] . '</font>'; 
}    else {
  echo '<font class="like"> ' . $rows['yes'] . '</font> - <font class="dislike"> ' . $rows['no'] . '</font>'; 
?>

</td>

</tr>

</table>
<hr color="#F0F0F0">
<?
}}
mysql_close(); //close database
?>


</center></td>
<td width="25%"></td>
</tr>

</table>

</td>

</tr>

</table>

</body>
</html>

Link to comment
Share on other sites

line 62. youve got a concatenator on the end of the line. should be:

  echo '<a href="like-exec.php?postid=' . $rows['id'] . '&url=member-index.php"><img src="resources/tick.png" alt="Like" border="0"></img></a><font class="like"> '; 

Link to comment
Share on other sites

ok it worked on the first post that shows up but everyone after that it says:

 

Warning: mysql_query() [function.mysql-query]: Can't connect to MySQL server on 'localhost' (10061) in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 66

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 66

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 68

 

Warning: mysql_close(): no MySQL-Link resource supplied in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 73

 

and right at the bottom it says:

 

 

Warning: mysql_close(): no MySQL-Link resource supplied in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 89

 

Link to comment
Share on other sites

its more than likely because the sql is in a loop and referencing the same sql connection. try:

<?php
require_once('auth.php');
?>
<?php $id = $_SESSION['SESS_MEMBER_ID'] ?>
<html>
<head>
<title>Announcement</title>
</head>
<body>

<table border="0" width="100%" height="100%">

<tr height="15%">
<td colspan="5"><?php include "header.php"; ?></td>
</tr>

<tr> 

<td>

<table border="0" width="100%" height="100%">

<tr>
<td width="25%" valign="top"><div valign="top"><?php include "menu.php"; ?></div></td>
<td width="50%" valign="top"><center>
<center><div class="subheading"><b>All Networks</b></div></center>

<?php

$host="1*2.*0.1*3.2*"; // Host name 
$username="martin9t9"; // Mysql username 
$password="***"; // Mysql password 
$db_name="martin9t9"; // Database name 
$tbl_name="post"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 

$sql="SELECT * FROM martin9t9.$tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
$i = 0;
while($rows=mysql_fetch_array($result)){
?>

<table border="0" width="100%">

<tr>
<td rowspan="2" width="45" height="45"> </td>
<td colspan="2"><a href="view-profile.php?uid=<?php echo $rows['uid'] ?>" class="postname"><? echo $rows['first']; ?> <? echo $rows['last']; ?></a> on <a class="postname"><? echo $rows['network']; ?></a></td>
</tr>
<?php $network = $rows['network']; $postid = $rows['id']; ?>
<tr>
<td><div class="post"><? echo $rows['post']; ?></div></td>
<td width="45"></td>
</tr>

<tr>
<td colspan="3" class="text" align="right"> 

<?php 
  if($rows['user'] !== $_SESSION['SESS_USER']) {
  echo '<a href="like-exec.php?postid=' . $rows['id'] . '&url=member-index.php"><img src="resources/tick.png" alt="Like" border="0"></img></a><font class="like"> '; 
  

$sql.$i="SELECT SUM(yes) as total FROM martin9t9.rating WHERE postid='$postid'";
$result.$i=mysql_query($sql.$i);

while($rows.$i=mysql_fetch_array($result.$i)){

echo $rows.$i['total']; 

}
mysql_close(); //close database 
  
   
echo   '</font> - <a href="dislike-exec.php?postid=' . $rows.$i['id'] . '&url=member-index.php&like=' . $rows.$i['no'] . '"><img src="resources/cross.png" alt="Dislike" border="0"></img></a> <font class="dislike"> ' . $rows.$i['no'] . '</font>'; 
}    else {
  echo '<font class="like"> ' . $rows.$i['yes'] . '</font> - <font class="dislike"> ' . $rows.$i['no'] . '</font>'; 
?>

</td>

</tr>

</table>
<hr color="#F0F0F0">
<?
}}
mysql_close(); //close database
?>


</center></td>
<td width="25%"></td>
</tr>

</table>

</td>

</tr>

</table>

</body>
</html>

Link to comment
Share on other sites

ok didnt work its showing up ALOT of

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\7833904\html\announcement\admin\member-index.php on line 68

 

it just keeps loading more and more and isnt showing any of my posts anymore

 

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.