Jump to content

Recommended Posts

Alright so the coding I have on one page allows you to submit requests into 'associations' on our game. My issue is that it's showing all 'horses', including ones that were already registered with that specific 'association', instead of showing just horses that have not been registered with that 'association'. I would have been able to code this myself [ i know VERY LITTLE php yet own a game that coded in php, go figure? ] if the associations were listed under the mysql table horsedata only. Instead the associations are listed under 'Registrations'.

 

So basically I have these two tables on mysql; horsedata & Registrations -- The code below is what shows all the horses..but I just want the horses that have not been registered with that association previously to show up. Unfortunately for me, it's on a table other than horsedata...

 

I guess bottom line is...how do i get it to check and see if the horse hasn’t been registered with the association which is on another mysql table? Sorry to make this so confusing, I was trying to make more sense of it O.O

 

Code which gets all horses

<?php

$hid=$_GET['id'];

$sql="SELECT * FROM horsedata WHERE Owner='$id'";
$result=mysql_query($sql);

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

  
$horseid=$r["id"];
   $name=$r["Name"];
$assoid=$_GET['id'];
   

  
   echo "<center> <form action='association_apply.php' method='post'> <input type='hidden' value='$horseid' name='horseid'> <input type='hidden' value='$assoid' name='assoid'> <input type='submit' value='$name'></form> </center> ";

}?>

 

Mysql Registration table info:  id [for when a horse was registered], assoname [name of the association], assoid [association id number], horseid [id of the horse]

Link to comment
https://forums.phpfreaks.com/topic/149163-cant-combined-two-mysql-tables/
Share on other sites

the result i want is for the horses who are already in the association to not show up on the list to register.

 

as of right now they all show up, i just want the ones that havent been registered in a specific assoication to showu p.

$sql="SELECT * FROM horsedata 
LEFT JOIN Registration ON Registration.horseid = horsedata.horseid
WHERE Owner='$id' AND Registration.assoname != 'specific association'";

 

<?php

$assoname=$_GET['assoname']; 

$sql="SELECT * FROM horsedata 
LEFT JOIN Registration ON Registration.horseid = horsedata.horseid
WHERE Owner='$id' AND Registration.assoname != '$assoname'";

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

  
$horseid=$r["id"];
   $name=$r["Name"];
$assoid=$_GET['id'];
   

  
   echo "<center> <form action='association_apply.php' method='post'> <input type='hidden' value='$horseid' name='horseid'> <input type='hidden' value='$assoid' name='assoid'> <input type='submit' value='$name'></form> </center> ";

}?>

 

Now this code its semi-functional seeing is there is no errors, but the horses that are not registered in the association are not showing up.

your playing games.lol

<?php

$assoname=$_GET['assoname']; 

$sql="SELECT * FROM horsedata 
LEFT JOIN Registration ON Registration.horseid = horsedata.horseid
WHERE Owner='$id' AND Registration.assoname != '$assoname'";

$result=mysql_query($sql)or die(mysql_error());

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

  
$horseid=$r["id"];
   $name=$r["Name"];
$assoid=$_GET['id'];
   

  
   echo "<center> <form action='association_apply.php' method='post'> <input type='hidden' value='$horseid' name='horseid'> <input type='hidden' value='$assoid' name='assoid'> <input type='submit' value='$name'></form> </center> ";

}?>

better try this then i say.

<?php

$assoname=$_GET['assoname']; 

$sql="SELECT * FROM horsedata,Registration
LEFT JOIN Registration ON Registration.horseid = horsedata.horseid
WHERE Owner='$id' AND Registration.assoname != '$assoname'";

$result=mysql_query($sql)or die(mysql_error());

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

  
$horseid=$r["id"];
   $name=$r["Name"];
$assoid=$_GET['id'];
   

  
   echo "<center> <form action='association_apply.php' method='post'> <input type='hidden' value='$horseid' name='horseid'> <input type='hidden' value='$assoid' name='assoid'> <input type='submit' value='$name'></form> </center> ";

}?>

ahha! I found the error

 

typo on my part but now the ids are just repeating themselves over and over and over

 

<?php

$assoname=$_GET['assoname']; 

$sql="SELECT * FROM horsedata 
LEFT JOIN registration ON registration.horseid = horsedata.id
WHERE Owner='$id' AND registration.assoname != '$assoname'";

$result=mysql_query($sql)or die(mysql_error());

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

  
$horseid=$r["id"];
   $name=$r["Name"];
$assoid=$_GET['id'];
   

  
   echo "<center> <form action='association_apply.php' method='post'> <input type='hidden' value='$horseid' name='horseid'> <input type='hidden' value='$assoid' name='assoid'> <input type='submit' value='$name'></form> </center> ";

} ?> 

what this do please a guess i take it lol.

probably wrong syntax....

 

 


<?php

$sql="SELECT  registration.horseid,registration.assoname
             ,horsedata.id,horsedata.Owner
              FROM horsedata,registration
              WHERE 
              registration.horseid = horsedata.id
              AND
              horsedata.Owner='$id' 
             AND 
             registration.assoname != '$assoname'";

?>

oops

add GROUP BY horsedata.id to the end of query

 

well now its not repeating but its still showing all horses, ones that are already apart of the association, and the ones that arnt apart of the association, but i just need to be able to see the ones that are not in the association

wait, i lied, its only showing horses that ARE registered, I need it to be the opposite where you see only horses that are not registered and the ones that are, you cant see.

 

 

Edit:

 

this is odd...theres like 3 horses that are not registered to the association im looking at, that show up, the rest are already registered, but then theres like 10 horses that are not registered that dont show up at all.

$sql="SELECT * FROM horsedata 
LEFT JOIN registration ON registration.horseid = horsedata.id
WHERE Owner='$id' AND (registration.assoname != '$assoname' OR ISNULL(registration.assoname)) 
GROUP BY horsedata.id";

 

now all are showing up...so i just need a code that will make it so the hroses that are registered already dont show up

now its working but it errors the code following it now, because its not inserting the horseid:

 

<?php

include 'header.php';

$sql="INSERT INTO assorequest (horseid, assoid, ownerid)
VALUES
('$_POST[horseid]','$_POST[assoid]','$id')";
if (!mysql_query($sql))
  {
  die('You have already submitted a request to this association from this horse'); include 'footer.php'; exit;}

echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Registration Request Submitted</b></font><BR><BR>";

?>

<?php

include 'footer.php';

?>

my bash.

<?php

include 'header.php';

$sql="INSERT INTO assorequest (horseid, assoid, ownerid)
VALUES
('{$_POST['horseid']}','{$_POST['assoid']}','$id')";
if (!mysql_query($sql))
  {
  die('You have already submitted a request to this association from this horse'); include 'footer.php'; exit;}

echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Registration Request Submitted</b></font><BR><BR>";

?>

<?php

include 'footer.php';

?>

my bash.

<?php

include 'header.php';

$sql="INSERT INTO assorequest (horseid, assoid, ownerid)
VALUES
('{$_POST['horseid']}','{$_POST['assoid']}','$id')";
if (!mysql_query($sql))
  {
  die('You have already submitted a request to this association from this horse'); include 'footer.php'; exit;}

echo "<BR><BR><font size='5pt' face='comic sans ms'><B>Registration Request Submitted</b></font><BR><BR>";

?>

<?php

include 'footer.php';

?>

 

still inserts a blank horse id

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.