View Full Version : Joining Tables
SilverDragonTears
04-09-2012, 11:05 PM
Yes I changed $pet to $row
$row = $adopts->join("adoptables", "adoptables.type = owned_adoptables.type")->select("owned_adoptables", array(), constant("PREFIX")."owned_adoptables.aid = '{$aid}'")->fetchObject();
if($row->currentlevel == '6') {
$article_content .="<p align='justify'>{$row->adultdescript}";
}else if($row->currentlevel == '5') {
$article_content .="<p align='justify'>{$row->hatchmdescript}";
}else if($row->currentlevel == '4') {
$article_content .="<p align='justify'>{$row->hatchdescript}";
}else if($row->currentlevel <= '3') {
$article_content .="<p align='justify'>{$row->description}";
}
Hall of Famer
04-09-2012, 11:24 PM
Well the problem may be with the $aid in the where clause. As I said before, this was just a rough example. It assumes that your adoptables id are stored in variable $aid, if the variable name is not $aid, or that you aint using adoptables id to fetch information, you will need to modify the where clause.
SilverDragonTears
04-09-2012, 11:26 PM
What should I change it to? I'm lost about it..
Edit: I don't give myself enough credit...
constant("PREFIX")."owned_adoptables.aid = '{$id}'") That worked. I have another issue... Should I make a new thread? Dragons won't show up in siggies
Hall of Famer
04-09-2012, 11:34 PM
Oh dragons wont show up in siggy? The same adoptables id problem? Check if you get rid of is_numeric() from every php page. XD
SilverDragonTears
04-09-2012, 11:36 PM
Don't I just need to make sure it's not in siggy.php? Which I did...
Hall of Famer
04-09-2012, 11:55 PM
I do not have this problem from the demo site, nor do I have trouble using bbcodes from TOD.
SilverDragonTears
04-09-2012, 11:59 PM
Test:
http://taleofdragons.net/get/4G6jD.gif (http://taleofdragons.net/levelup.php?id=4G6jD)
What on earth....
Hall of Famer
04-10-2012, 12:04 AM
So you see? Its not a problem at all. XD
SilverDragonTears
04-10-2012, 12:12 AM
LoL... I must be tired!
Hall of Famer
04-10-2012, 12:20 AM
Alright guess thats it, I understand the frustration of having to start over when you already have a community with 500 members and 2500 posts. You must be overexhausted, take a rest now if you have to. XD
SilverDragonTears
04-10-2012, 12:38 AM
One more thing and then I surely will. This sort script worked fine on my old site... Now it's telling me Fatal error: Call to a member function fetchObject() on a non-object in /home/taleofdr/public_html/sort.php on line 51
<?php
include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("classes/class_pagination.php");
include("css/pagination.css");
include("inc/sort.php");
include("inc/lang.php");
//***************//
// START SCRIPT //
//***************//
$id = $_GET["id"];
$act = $_GET["act"];
$more = $_GET["more"];
$page = $_GET["page"];
if($isloggedin == "yes")
{
$article_content = "<p id='activate_sort' style='cursor: pointer'>
Click here to sort your dragons
</p>
<table>";
// We need to get all of the user's adoptables from the database and display them...
$query = "SELECT *
FROM {$prefix}owned_adoptables
LEFT JOIN {$prefix}sort_adoptables
ON {$prefix}owned_adoptables.aid = {$prefix}sort_adoptables.adoptable_id
INNER JOIN {$prefix}levels
ON {$prefix}levels.thisislevel = {$prefix}owned_adoptables.currentlevel
INNER JOIN {$prefix}adoptables
ON {$prefix}owned_adoptables.type = {$prefix}adoptables.type
WHERE {$prefix}owned_adoptables.owner = '{$loggedinname}'
AND {$prefix}levels.adoptiename = {$prefix}adoptables.type
ORDER BY {$prefix}sort_adoptables.sorting_id";
$stmt = $adopts->query($query);
$cols = 6; //the number of columns
do{
$article_content .= "<tr>";
for($i=1;$i<=$cols;$i++){
if($row = $stmt->fetchObject()){
if($row->usealternates == 'yes') $image = $row->alternateimage;
else $image = $row->primaryimage;
if($row->currentlevel == 0) $image = $row->eggimage;
if($image=='') $image = $row->primaryimage;
$article_content .= " <td class='sortable_adoptables' style='width: 40px;'>
<table id='orderaid_{$row->aid}'><tr>
<td><img src='{$image}' width='30px' height='30px'><br>{$row->name}</td>
</tr> </table></td>";
}
else{
$article_content .= "<td> </td>"; //If there are no more records at the end, add a blank column
}
}
} while($row);
$article_content .= "</table>";
}
//***************//
// OUTPUT PAGE //
//***************//
echo showpage($article_title, $article_content, $date);
?>
Hall of Famer
04-10-2012, 12:51 AM
Well replace every {$prefix} by ".constant('PREFIX')." and it should work for you. The reason why we are using PHP constants is that we do not need to define superglobals for database information used in functions and classes. You do not see $GLOBALS['prefix'] anymore from functions in Mys v1.3.1. Once the User class is available we will get rid of more superglobals, although some superglobals will always remain, such as $GLOBALS['adopts'] since you cannot define a constant object.
SilverDragonTears
04-10-2012, 12:54 AM
See, I must be tired. I tried that before I posted and I must have missed one b.c it still wasn't working. Thank you for all your help tonight HoF :) My members will thank you!
Hall of Famer
04-10-2012, 01:08 AM
Still the same error? Post your script file after you've modified the SQL query using constants, I will see if something else is wrong.
SilverDragonTears
04-10-2012, 01:14 AM
No it's working now :) The only issue I'm having now is I don't think that the sort id's are updating into the db
<?php
include("functions/functions.php");
include("functions/functions_users.php");
include("functions/functions_adopts.php");
include("classes/class_pagination.php");
include("css/pagination.css");
include("inc/lang.php");
//***************//
// START SCRIPT //
//***************//
if ($_POST)
{
$userID = $_COOKIE['auid'];
foreach($_POST['orderaid'] as $orderID => $aid)
{
$adopts->query('REPLACE INTO ' . $prefix . 'sort_adoptables (`user_id`, `adoptable_id`, `sorting_id`)
VALUES ("' . addslashes($userID) . '", "' . addslashes($aid) . '", "' . addslashes($orderID) . '")');
}
echo '<p>Adoptables have been rearranged</p>';
}
?>
Hall of Famer
04-10-2012, 01:19 AM
Of course its not updating the database when you still use $prefix in your sql query. XD
SilverDragonTears
04-10-2012, 01:19 AM
I changed it to $adopts->query('REPLACE INTO ' . ".constant('PREFIX')." . 'sort_adoptables (`user_id`, `adoptable_id`, `sorting_id`)
VALUES ("' . addslashes($userID) . '", "' . addslashes($aid) . '", "' . addslashes($orderID) . '")');
}
and still not working. I pasted the wrong one!
Hall of Famer
04-10-2012, 01:26 AM
Well the cookie definition has changed, use $_COOKIE['mysuid'] instead of $_COOKIE['auid']. Honestly the code you posted above should not even work in Mys v1.3.0 security release. I strongly recommend you not to use cookie superglobals to convey information, since I may end up encrypting cookies in future to improve security(so if a hacker steals your cookie, he still gets nothing out of it but a string that makes no sense). When this happens, you will not get anything out of it. Theres no way to decrypt by writing a PHP script.
SilverDragonTears
04-10-2012, 01:29 AM
lol, Still not working :catfish:
Hall of Famer
04-10-2012, 01:32 AM
Well try to debug by echoing the $COOKIE['mysuid'] to the screen, see what it stores. Theres a chance I already encrypted uid in cookies, and if this happens you cannot hope to use cookies as information. Like I said before, its bad practice to use cookies to fetch information such as user id, username and password unless its used internally by the script to compare hashes.
SilverDragonTears
04-10-2012, 01:40 AM
If I did it right
echo '<p>Adoptables have been rearranged'.$_COOKIE->mysuid.'</p>';
then it only printed Adoptables have been rearranged.
Hall of Famer
04-10-2012, 01:41 AM
Oh nope, the $COOKIE is a superglobal array, its not an object. You need to use {$COOKIES['mysuid']} here, if you need me to explain to you what are the differences of objects and arrays I am glad to help.
SilverDragonTears
04-10-2012, 01:46 AM
It's not echoing anything still
Hall of Famer
04-10-2012, 01:53 AM
I see, then guess what? Do not use $_COOKIE at all, try to select uid from table prefix.users and it will work this way. In next release I will enable $_SESSION to store uid and username for almost every page, so you will be using sessions instead of cookies. For now, you have to write a code to fetch uid from database.
SilverDragonTears
04-10-2012, 01:54 AM
How do I do that? Sorry very tired here :(
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.