Jump to content

innovatio

Members
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

0 Neutral

About innovatio

  • Rank
    Member
  1. So my schema goes along something like this: Table: foobar foo: words specific to foo bar: words specific to bar The query basically selects the querys with common "keywords" found in $keywords. The schema layout isn't bad at all. What I am trying to do is to display the matched records in random order.
  2. Dear sir, you have brought sunlight unto my problems. It is solved! I am still new to php and have been wracking my brain over this for weeks, and you, my deux ex machina, have saved me. Thank you so much! So now I can query anything relating to user #2 by referencing to intval($_POST['id']), correct? Merci beaucoup, monsieur .
  3. I did so but nothing has changed in terms of the output.
  4. By doing that, I get the following: Sorry, contact could not go through. Try again later. array(2) { ["id"]=>string(1)"2"["message"]=>string(7)"Message"} I think this maybe due to the way conditions are read on the receiving end: if(isset($_POST['id']) && is_numeric($_POST['id'])) { Though the confusing part is that the ["id"] being outputted is the correct id position of the user I was trying to get, so I don't know why it isn't outputting this part: if(isset($_POST['id']) && is_numeric($_POST['id'])) { // run query to get first_name where the submitted record id matches // $toCD = "SELECT `first_name` FROM `users` WHERE `id` =" .intval($id); $toST = $con->query('SELECT first_name FROM users WHERE id = ' . intval($id)); // make sure a row was return if($toST->num_rows === 1) { $row = $toST->fetch_assoc(); echo "<div class = 'prep_stmt'>Your message to".$_row['first_name']."...</div>"; } I tried it with another user, and I get the same results. The id stored in the array is correct, but it isn't executing the right conditions.
  5. I realized I didn't update my code previously. Here is what I have so far: on list.php: <?php if ($searchST) { while ($row = $searchST->fetch_assoc()) { echo '<div class="z">'; echo '<div class="x">'; echo '<div class="y">'; echo '<div class="text_info">'; echo "<div id='input_titles'>C1</div><textarea readonly name='c1' id='a' rows='3' cols='54' maxlength='162' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c1"]."</textarea><br />"; echo "<div id='input_titles'>C2</div><textarea readonly name='c2' id='a' rows='3' cols='54' maxlength='162' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c2"]."</textarea><br />"; echo "<div id='input_titles'>C3</div><textarea readonly name='c3' id='a' rows='15' cols='54' maxlength='810' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c3"]."</textarea><br />"; echo "<div id='input_titles'>C4</div><textarea readonly name='c4' id='a' rows='2' cols='54' maxlength='108' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c4"]."</textarea>"; echo '</div>'; echo '<div class="visual_info">'; echo '<div class="p_pic_image">'; echo "<img src='".$row["pic"]."' id='p_pic'> "; echo '</div>'; echo '<div class="country_and_name">'; echo "<textarea readonly name='country' id='country' rows='1' cols='14'>".$row["country"]."</textarea>"; echo "&nbsp".$row["first_name"]; echo '</div>'; echo '</div>'; echo '<form action="compose.php" method="POST">'; echo '<input type="hidden" name="id" value="'.$row['id'].'" />'; //the insert echo '<input type="submit" name="message" id="message" value="Message">'; echo '</form>'; echo '</div>'; echo '</div>'; echo '</div>'; if (isset($_POST['message'])) { $carry = "SELECT `first_name` FROM `users`"; $carryST = $con->query($carry); if($carryST) { while ($row = $carryST->fetch_assoc()) { $_SESSION['to_name'] = $row["first_name"]; $_SESSION['to_id'] = $row["id"]; } } $carryST->close(); header("location: compose.php"); exit(); } echo '</form>'; } } $searchST->close(); } else { } And on the receiving end, compose.php: <?php if(isset($_POST['id']) && is_numeric($_POST['id'])) { // run query to get first_name where the submitted record id matches // $toCD = "SELECT `first_name` FROM `users` WHERE `id` =" .intval($id); $toST = $con->query('SELECT first_name FROM users WHERE id = ' . intval($id)); // make sure a row was return if($toST->num_rows === 1) { $row = $toST->fetch_assoc(); echo "<div class = 'prep_stmt'>Your message to".$_row['first_name']."...</div>"; } else { // record id does not exist. Output error message echo "<div class = 'prep_error'>Sorry, contact could not go through. Try again later.</div>"; } } ?>
  6. The <form> tags containing your suggested input hidden field are at the end of the "echo" tirade. So I will remove the "if (isset($_POST))" code concerning the message button because I understand now that the session method will not get me anywhere. I do not want to pass over the textarea information, just the name and id so I can use those as reference variables when calling a query. Yes, you are correct in that "compose.php" is my receiving page, and by the names of my php pages, you may have already observed that I coding towards a contact -> message system. On the receiving page, the error message shows, to my comfort that at least something is working, and am now trying to get the "isset()" and "isnumeric" conditions to work. And I did just that. I removed the outer <form> tags and kept the inner <form> tags located towards the end of the "echo" repeats and inserted the hidden field under that. So now it looks like echo '<form action="compose.php" method="POST">'; echo '<input type="hidden" name="id" value="'.$row['id'].'" />'; echo '<input type="submit" name="message" id="message" value="Message">'; echo '</form>'; With the receiving page looking like this: <?php if(isset($_POST['id']) && is_numeric($_POST['id'])) { // run query to get first_name where the submitted record id matches $toCD = "SELECT `first_name` FROM `users` WHERE `id` =" .intval($id); $toST = $con->query($toCD); // make sure a row was return if($toST->num_rows === 1) { $row = $toST->fetch_assoc(); echo "<div class = 'prep_stmt'>Your message to".$_row['first_name']."...</div>"; } else { echo "<div class = 'prep_error'>Sorry, contact could not go through. Try again later.</div>"; // record id does not exist. Output error message } } ?> Your explanations are really helpful, by the way. I am starting to realize the logic behind the networking required and what I am up against.
  7. I've tried integrating what you suggested, but nothing seems to be outputting on the receiving page. Here is my attempt at the merge: list.php <?php if ($searchST) { while ($row = $searchST->fetch_assoc()) { echo '<div class="z">'; echo '<div class="x">'; echo '<div class="y">'; echo '<div class="text_info">'; echo "<div id='input_titles'>C1</div><textarea readonly name='c1' id='a' rows='3' cols='54' maxlength='162' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c1"]."</textarea><br />"; echo "<div id='input_titles'>C2</div><textarea readonly name='c2' id='a' rows='3' cols='54' maxlength='162' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c2"]."</textarea><br />"; echo "<div id='input_titles'>C3</div><textarea readonly name='c3' id='a' rows='15' cols='54' maxlength='810' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c3"]."</textarea><br />"; echo "<div id='input_titles'>C4</div><textarea readonly name='c4' id='a' rows='2' cols='54' maxlength='108' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c4"]."</textarea>"; echo '</div>'; echo '<div class="visual_info">'; echo '<div class="p_pic_image">'; echo "<img src='".$row["pic"]."' id='p_pic'> "; echo '</div>'; echo '<div class="country_and_name">'; echo "<textarea readonly name='country' id='country' rows='1' cols='14'>".$row["country"]."</textarea>"; echo "&nbsp".$row["first_name"]; echo '</div>'; echo '</div>'; echo '<form action="list.php" method="POST">'; echo '<input type="submit" name="message" id="message" value="Message">'; echo '</form>'; echo '</div>'; echo '</div>'; echo '</div>'; if (isset($_POST['message'])) { $carry = "SELECT `first_name` FROM `users`"; $carryST = $con->query($carry); if($carryST) { while ($row = $carryST->fetch_assoc()) { $_SESSION['to_name'] = $row["first_name"]; $_SESSION['to_id'] = $row["id"]; } } $carryST->close(); header("location: compose.php"); exit(); } echo '</form>'; } } $searchST->close(); } else { } And the receiving page: <header> <?php if(isset($_POST['id']) && is_numeric($_POST['id'])) { // run query to get first_name where the submitted record id matches $toCD = "SELECT `first_name` FROM `users` WHERE `id` = intval($id)"; $toST = $con->query($toCD); // make sure a row was return if($toST->num_rows === 1) { $row = $toST->fetch_assoc(); echo "<div class = 'prep_stmt'>Your message to".$_row["first_name"]."...</div>"; } else { // record id does not exist. Output error message } } ?> </header> Nothing is outputting. I also incorporated Barand the Guru's suggestion of removing the first <form> tags while keeping the second <form> tags surrounding the submit button.
  8. I wish to execute a REGEXP search but by a random mechanism. I've used ORDER BY RAND() before but it is getting too performance costly to where I am to evolve to other methods. Here is the REGEXP function in question: $searchCD = "SELECT * FROM `table` WHERE `foo` ||', '|| `bar` REGEXP '".$keywords."' "; $searchST = $con->query($searchCD); The alternative order random I wish to splice it with: The SELECT quote FROM quotes LIMIT $generated_number, X from the blog post here: http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/ I've tried numerous times to splice the two methods myself, but nothing works. I would consider other methods, but I don't know how to approach the issue of my database containing missing records from deleted accounts. Thanks!
  9. If I am calling an undistinguishable amount of records from a database through a while loop, and with each record called a submit button is accompanied with it, how can I get each submit button to respond exclusively to its respective iterated record? A visual of what I am trying to achieve: In the logic behind this, each "Contact" button is linked to its adjacent profile. So, if I click on the "Contact" button next to "Lily," Lily's name is passed on to the next page. However, so far I am met with this: Where no matter which "Contact" button I press, the name of the last iteration is passed on. In this case, even I clicked on "Lily"'s contact button, the name of the last/highest iteration, "Jane", is passed on to the next page. Here is the code I am stuck with: list.php: <?php session_start(); require_once( "./inc/connect.inc.php"); if(!isset($_SESSION["email_login"])) { header("location: index.php"); } else { } ?> <?php if ($searchST) { while ($row = $searchST->fetch_assoc()) { echo '<form action="list.php" method="POST">'; echo '<div class="z">'; echo '<div class="x">'; echo '<div class="y">'; echo '<div class="text_info">'; echo "<div id='input_titles'>C1</div><textarea readonly name='c1' id='a' rows='3' cols='54' maxlength='162' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c1"]."</textarea><br />"; echo "<div id='input_titles'>C2</div><textarea readonly name='c2' id='a' rows='3' cols='54' maxlength='162' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c2"]."</textarea><br />"; echo "<div id='input_titles'>C3</div><textarea readonly name='c3' id='a' rows='15' cols='54' maxlength='810' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c3"]."</textarea><br />"; echo "<div id='input_titles'>C4</div><textarea readonly name='c4' id='a' rows='2' cols='54' maxlength='108' onCopy='return false' onDrag='return false' onDrop='return false' onPaste='return false' autocomplete='off'>".$row["c4"]."</textarea>"; echo '</div>'; echo '<div class="visual_info">'; echo '<div class="p_pic_image">'; echo "<img src='".$row["pic"]."' id='p_pic'> "; echo '</div>'; echo '<div class="country_and_name">'; echo "<textarea readonly name='country' id='country' rows='1' cols='14'>".$row["country"]."</textarea>"; echo "&nbsp".$row["first_name"]; echo '</div>'; echo '</div>'; echo '<form action="network.php" method="POST">'; echo '<input type="submit" name="message" id="message" value="Message">'; echo '</form>'; echo '</div>'; echo '</div>'; echo '</div>'; if (isset($_POST['message'])) { $carry = "SELECT `first_name` FROM `users`"; $carryST = $con->query($carry); if($carryST) { while ($row = $carryST->fetch_assoc()) { $_SESSION['to_name'] = $row["first_name"]; $_SESSION['to_id'] = $row["id"]; } } $carryST->close(); header("location: compose.php"); exit(); } echo '</form>'; } } $searchST->close(); } else { } The page the name of a given profile is supposed to pass through(compose.php): <body> <div class="wrapper"> <header> <?php echo $_SESSION["to_name"]; ?> <?php echo $_SESSION["to_id"]; ?> <div class = "prep_stmt">Your message to <?php $_SESSION["to_name"]; ?>...</div> </header> </div> </body> I know that the session variable is constantly being replaced, but I don't know to approach this. I won't know the exact number of users either so I can't make any absolute forms.
×
×
  • 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.