Jump to content
MakeWebGames

heavily modifying but need help on 1 part


Recommended Posts

Posted

hey i have decided that i will rely on this website less, as i really wanna learn to code & dont wanna make turning to help a habit, but i do need one last help, i am trying convert proposals.php into a sensei system. where you can ask 3 people to be your students & they display on profile. i just need help on how to make it so the limti is 3 & not one??? heres a snippet of code from proposals.php

if($ir['married'])
  {
    echo 'You are already married!';
    $h->endpage();
    exit; 
Posted

lets break it down

$ir is the global function for the users mysql table

Check if married is a INT value in the users table. If not you will need to change it

Then all you need to do is change it from checking 1 as it is in the code you posted to checking if the value is 3

if($ir['married'] == 3)

Posted

married in the users table is a INT, the INT is the userid of who you are married to tho. so if i changed it to 3 wouldnt it check to see if your affiliated with player id 3??

Posted

Based on what you have that is correct....

What you could do here is when a proposal is accepted you add one to that field. Then you store the associated player in a different table and call that data when needed.

Posted (edited)

You could alternatively do something like

* Ignore the <br />'s in the code if they appear.

 

ALTER TABLE `users` ADD `sensei` VARCHAR(25) NOT NULL DEFAULT '';

Then do something like

$sensei = explode(",", $ir['sensei']);
$count = count($sensei);
echo "<strong>You have ". $count ." students</strong>";
while($count > 0)
 {
   $count--;
   $r = mysql_fetch_array( mysql_query("SELECT `username` FROM `users` WHERE `userid`=". $sensei[$count] ));
   echo "<a href='viewuser.php?ID=". $sensei[$count] ."'>". $r['username'] ."</a>";
 }

 

And then insert the records something like

function senseiUpdate($user)
 {
    global $userid, $ir;
    //Check if they already have 3 students
    $countSensei = count( explode(",", $ir['sensei']) );
    if($countSensei == 3)
       {
           //return TRUE;
           exit;
        }
   /*
     At this moment in time, the `sensei` value has nothing in it, but we need to check it
     otherwise, we may have a value of "  , 4, "
   */
    $msg = "Sucessfully added as a student!";
    return $msg;
   $checkSensei = substr($ir['sensei'], 1, 1); //Get first char in the row.
   if(!is_numeric($checkSensei))
      {
          return mysql_query("UPDATE `users` SET `sensei`=".$user." WHERE `userid`=$userid");
      }
  else
      {
         $newSensei = $ir['sensei'].','.$user; //Concat the records with the new one
         return mysql_query("UPDATE `users` SET `sensei`=".$newSensei." WHERE `userid`=$userid");
       }
 }

 

And finally, the usage

senseiUpdate($_POST['userid']); //For a _POST
senseiUpdate($student); //For a declared variable

 

Hope that helps

-sniko

Edited by sniko
Edited the code a little
Posted

ah! u always come through sniko thanx! ima fully examine it once i fix my comments again. while trying thing on my own, i messed up my comments on the viewuser page again. & i keep forgetting how i fixed it 1st 2 times lol.

Posted

ok i will & i just fixed, i looked through my old post on here & realized that in db comments are "gcomments" but in code i had "gComments" had to lower case the "c" lol. but im about to examine the code u shared earlier now.

Posted

im still working but this is what i have so far, basically i finally got rid of the limit on proposing to only 1 person. now i gotta see if u can have a multi relationship & will everyone appear on profile.

<?php

include("globals.php");
echo '<h1>Sensei Dojo</h1>';

function check() {
global $ir, $h;
 if($ir['student']== 3)
  {
    echo 'You already have 3 students!';
    $h->endpage();
    exit;
  }
}
check();
if(isset($_GET['propose'])) {
$_POST['ID'] = abs(@intval($_POST['ID']));
if($_POST['ID']) {
 mysql_query("INSERT INTO proposals VALUES('','{$ir['userid']}','{$_POST['ID']}')") or die(mysql_error());
 $i=mysql_insert_id($c);
 event_add($_POST['ID'],"{$ir['username']} Just asked you to be their student. <br><br><a href=proposal.php?donow=accept&id={$i}>Accept</a> | <a href=proposal.php?donow=decline&id={$i}>Decline</a>");
 echo 'request has been sent to id '.$_POST['ID'].'.';
 $h->endpage();
 exit;
}
$a = mysql_query("SELECT * FROM proposals WHERE proposer='{$ir['userid']}'") or die(mysql_query());
if(mysql_num_rows($a) == 3) { echo 'You already have a request sent!<br><br>If you can not find this request to cancel please go look at the proposals you have sent.'; 
$h->endpage(); 
exit; }
$c = mysql_query("SELECT * FROM proposals WHERE proposed='{$ir['userid']}'") or die(mysql_query());
if(mysql_num_rows($c) > 0) { echo 'You already have a request you have not declined or accepted.<br><br>If you can not find this requested please look at your requested that has been sent to you with out accepting or decline.'; $h->endpage(); exit; }
echo '
 <form action="?propose" method="post">
  User id to propose to: <input type="text" name="ID">
  <br><input type="submit" value="Submit">
 </form>';
$h->endpage();
exit;
}
if(isset($_GET['viewproposalrecieved'])) {
if($_GET['id']) {
 $db->query("DELETE FROM proposals WHERE id='{$_GET['id']}'") or die(mysql_error());
 echo 'request declined';
 exit;
}
echo '
<table border=1 width=100%>
 <tr>
  <th>User Requested For</th>
  <th>Actions</th>
 </tr>';
$t = mysql_query("SELECT * FROM proposals WHERE proposed='{$ir['userid']}'") or die(mysql_error());
if(mysql_num_rows($t) == 0) { echo '<td colspan=2>No Request For You!</td></table>'; $h->endpage(); exit; }
 while($d = mysql_fetch_assoc($t)) {
  $b = mysql_query("SELECT * FROM users WHERE userid='{$d['proposed']}'") or die(mysql_error());
  $h = mysql_fetch_assoc($b);
  echo '
  <tr>
   <td>'.$h['username'].'</td>
<td><a href="?viewproposalrecieved&id='.$d['id'].'">Delete</a></td>';
 }
echo '</td></table>';
exit;
}
if(isset($_GET['viewproposalsent'])) {
if($_GET['id']) {
 $db->query("DELETE FROM proposals WHERE id='{$_GET['id']}'") or die(mysql_error());
 echo 'Proposal canceld';
 $h->endpage();
 exit;
}
echo '
<table border=1 width=100%>
 <tr>
  <th>User Requested For</th>
  <th>Actions</th>
 </tr>';
$t = mysql_query("SELECT * FROM proposals WHERE proposer='{$ir['userid']}'") or die(mysql_error());
if(mysql_num_rows($t) == 0) { echo '<td colspan=2>No Proposals Made by you!</td></table>'; $h->endpage(); exit; }
 while($d = mysql_fetch_assoc($t)) {
  $b = mysql_query("SELECT * FROM users WHERE userid='{$d['proposed']}'") or die(mysql_error());
  $h = mysql_fetch_assoc($b);
  echo '
  <tr>
   <td>'.$h['username'].'</td>
<td><a href="?viewproposalrecieved&id='.$d['id'].'">Delete</a></td>';
 }
echo '</td></table>';
$h->endpage();
exit;
}
if($_GET['donow'] == accept) {
$id = $_GET['id'];
$a = mysql_query("SELECT * FROM proposals WHERE id='{$id}'") or die(mysql_error());
$f = mysql_fetch_assoc($a);
if($f['proposed'] != $ir['userid']) {
 echo 'This request does not belong to you!';
 $h->endpage();
 exit;
}
mysql_query("UPDATE users SET sensei='{$f['proposer']}' WHERE userid='{$userid}'") or die(mysql_error());
mysql_query("UPDATE users SET sensei='{$ir['userid']}' WHERE userid='{$f['proposer']}'") or die(mysql_error());
mysql_query("UPDATE users SET student='student + 1' WHERE userid='{$f['proposer']}'") or die(mysql_error());
event_add($f['proposer'], "{$ir['username']} Accepeted your proposal.");
mysql_query("DELETE FROM proposals WHERE id='{$f['id']}'") or die(mysql_error());
echo 'You accepted the request!';
$h->endpage();
exit;
}
if($_GET['donow'] == decline) {
$id = $_GET['id'];
$a = mysql_query("SELECT * FROM proposals WHERE id='{$id}'") or die(mysql_error());
$f = mysql_fetch_assoc($a);
if($f['proposed'] != $ir['userid']) {
 echo 'This request does not belong to you!';
 $h->endpage();
 exit;
}
mysql_query("DELETE FROM proposals WHERE id='{$f['id']}'") or die(mysql_error());
event_add($f['proposer'], "{$ir['username']} Declined your proposal.");
echo 'You declined the request!';
$h->endpage();
exit;
}
echo '<a href="?propose">Request for a student</a><br>
     <a href="?viewproposalsent">View Your Sent request That Has Not Been Accepted/Declined</a><br>
  <a href="?viewproposalrecieved">View Your Recieved request That Has Not Been Aceppted/Declined</a>';
$h->endpage();
?> 
Posted
mysql_query("UPDATE users SET sensei='{$ir['userid']}' WHERE userid='{$f['proposer']}'") or die(mysql_error());

Knowing you are trying to allow each sensei to have 3 students, the above line sets the student as the sensei of the sensei..... if that makes much sense

1. Only update the sensei field of the student

2. Update the student field of the sensei

 

Also I see if you are a student of a sensei, you can still in turn be a sensei of 3 students of your own. Is this how it is suppose to be?

Posted

so would it be

 mysql_query("UPDATE users SET sensei='{$f['proposer']}' WHERE userid='{$userid}'") or die(mysql_error());
mysql_query("UPDATE users SET students=students + 1 WHERE userid='{$f['proposer']}'") or die(mysql_error() 

i just suppose to remove that line right???

Posted

YES its right! thank u so much Analog for watching me through this, now all i gotta do is make it so it appears on the viewuser.php page & then i gotta add to your reputation ;)

Posted

alright i examined but i have no idea as in WHERE to to start adding the code to make students appear.

//Star Of Marriage Script:
$v = mysql_query("SELECT * FROM users WHERE userid='{$r['married']}'") or die(mysql_error());
$vc = mysql_fetch_assoc($v);
if($r['married'] == 0) { $married = "<b>Married:</b> [<font color=red>No One</font>]<br>"; }
else if($r['married'] > 0) { $married = "<b>Married:</b> [<a href=?u={$vc['userid']}>{$vc['username']}</a>]<br>"; }
//End Of Marriage Script
$_GET['u'] = abs((int) $_GET['u']);
if(!$_GET['u'])
{
print "Invalid use of file";
}
else
{
$q=$db->query("SELECT u.*,us.*,c.*,h.*,g.*,f.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN cities c ON u.location=c.cityid LEFT JOIN houses h ON u.maxwill=h.hWILL LEFT JOIN gangs g ON g.gangID=u.gang LEFT JOIN fedjail f ON f.fed_userid=u.userid WHERE u.userid={$_GET['u']}");
if($db->num_rows($q) == 0)
{
print "Sorry, we could not find a user with that ID, check your source.";
}
else
{
$r=$db->fetch_row($q);
if ( !$r['married'] )
{
$marital="<font color='red'>No</font>";
}
else
{
$k=mysql_query("SELECT username FROM users WHERE userid={$r['married']}", $c);
$marital="<a href='http://bigbro.x10.mx/viewuser.php?u={$r['married']}' style='color:green;'>".mysql_result($k,0,0)."</a> ";
}
Posted (edited)

Just add this to the file you want to display the students in, then echo $students where you want it to display.

This is not tested!

 

$q = mysql_query("SELECT userid, username FROM users WHERE sensei = {$r['userid']}");
$students = "Students:";
$sep = 0;
if(!mysql_num_rows($q))
{
	$students .= " N/A";
}
while($stu = mysql_fetch_array($q))
{
	if($sep > 0)
		{
			$students .= " <a href='viewuser.php?u={$stu['userid']}'>{$stu['username']}</a>";
		}
	else
		{
			$students .= ", <a href='viewuser.php?u={$stu['userid']}'>{$stu['username']}</a>";
			$sep = 1;
		}
}
Edited by Analog
Stupid <br /> tags.... grrrrrr
Posted

@ Analog - You wouldn't need the comma on the following line

 

$students .= ", <a href='viewuser.php?u={$stu['userid']}'>{$stu['username']}</a>";

After the "

-sniko

Posted

lol, you are correct as I just noticed I put the comma on the wrong line. Like it is posted, if the player had 3 students it would display....

,student1 student2 student3

the 2 $students lines need switched around for what I had in my head

so that it displays like

student1, student2, student3

The comma is there to separate the user names if there is more than one.

As he is planning to have the ability to have up to 3 students.

Posted

if($ir['student']== 3)

{

echo 'You already have 3 students!';

$h->endpage();

exit;

}

You do know that you can have more then 3 students?

it's basically saying if the value is 3 in your table it will print that statement but if the value is 1,2,4,5,6 and so forth it wont print that...

== means that it has to be the value of 3 I think you were aiming for the greater than sign > ....

if($ir['student']> 3)

{

echo 'You already have 3 students!';

$h->endpage();

exit;

}

Posted

The way you suggest lucky would imply that just in case you go over 3 end it. In which case it would be >= 3

 

If its coded correctly it will never go over 3 and end so == 3 will suffice.

Posted (edited)
Just add this to the file you want to display the students in, then echo $students where you want it to display.

This is not tested!

 

$q = mysql_query("SELECT userid, username FROM users WHERE sensei = {$r['userid']}");
$students = "Students:";
$sep = 0;
if(!mysql_num_rows($q))
{
	$students .= " N/A";
}
while($stu = mysql_fetch_array($q))
{
	if($sep > 0)
		{
			$students .= " <a href='viewuser.php?u={$stu['userid']}'>{$stu['username']}</a>";
		}
	else
		{
			$students .= ", <a href='viewuser.php?u={$stu['userid']}'>{$stu['username']}</a>";
			$sep = 1;
		}
}

It says N/A even tho i have 1 student. hmmmm, im thinking it involves the line with mysql_query("SELECT userid, username FROM users WHERE sensei = {$r['userid']}");

or it could be cuz in db for the student it has the sensei's userid but for the sensei it just has the # of students. it could be cuz i dont have student in sensei associated on the sensei side.

Edited by Daron

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.   Paste as plain text instead

  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...