Jump to content

JackW

Members
  • Posts

    31
  • Joined

  • Last visited

About JackW

  • Birthday 10/18/1946

Contact Methods

  • Website URL
    http://www.panhandleyardsale.com/

JackW's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. JackW

    Query two tables?

    I think I need to put a second query in the loop. I had the below code in a previous version of php and it worked fine. Can't seem to make it work now in the updated version. What do I need to do differently? The below code only gets one line from the first table and non from the second table. <?php $db = @mysqli_connect('localhost', 'unsabook', 'Yearbook#1964', 'unsabook'); if (!$db) { echo "Error: " . mysqli_connect_error(); exit(); } $rs_message = $db->query ("SELECT * FROM `messages` ORDER BY `message_ID` DESC LIMIT 0,200"); while ( $message_array = $rs_message->fetch_assoc() ) { echo '<div>'; echo $message_array['message_ID']; echo 'Subject: <b>'; echo $message_array['subject']; echo '</b>'; echo ' Submitted by '; echo $message_array['name']; echo '<br>'; echo $message_array['message']; echo '<br></div>'; $rs_replies = mysql_query("SELECT * FROM replies WHERE message_ID = '" . $message_array['message_ID'] . "' ORDER BY `reply_ID` DESC"); while($replies_array = mysql_fetch_assoc($rs_replies)) { echo '<div class="indent">'; echo $replies_array['reply_ID']; echo '<b>Reply</b> '; echo 'Submitted by '; echo $replies_array['name']; echo '<br>'; echo $replies_array['message']; echo '</div>'; } } $db->close(); ?>
  2. JackW

    Query two tables?

    I have a MySQL data base with two tables. I need to query the second table to find related results from a query on the first table. Here is what I have, How do I get it to combine the two queries? <?php $db = @mysqli_connect('localhost', 'unsabook', 'Password', 'unsabook'); if (!$db) { echo "Error: " . mysqli_connect_error(); exit(); } $rs_message = $db->query ("SELECT * FROM `messages` ORDER BY `message_ID` ASC LIMIT 0,200"); while ( $message_array = $rs_message->fetch_assoc() ) { echo '<div class="left10">'; echo $message_array['message_ID']; echo ' &nbsp; '; echo $message_array['school']; echo ' &nbsp; '; echo $message_array['name']; echo ' &nbsp; '; echo $message_array['post_day']; echo ' &nbsp; '; echo $message_array['reply_day']; echo ' &nbsp; '; echo $message_array['subject']; echo ' &nbsp; '; echo $message_array['message']; //$message_ID = $message_array['message_ID']; echo '</div>'; } // 2nd table is below $rs_replies = $db->query ("SELECT * FROM `replies` WHERE `message_ID` = '".$message_ID."' ORDER BY `reply_ID` DESC"); while($reply_array = mysqli_fetch_assoc($rs_replies)) { echo '<div class="left10">'; echo $reply_array['reply_ID']; echo ' &nbsp; '; echo $reply_array['name']; echo ' &nbsp; '; echo $reply_array['message_ID']; echo ' &nbsp; '; echo $reply_array['reply_day']; echo ' &nbsp; '; echo $reply_array['message']; echo '</div>'; } $db->close(); ?>
  3. Thank you so much for your help. Jack
  4. Thank you. That is probably the problem. Some of the arrays contain only a single element while others have two elements separated by "|". Those that contain 2 elements need to be separated. How would I write it to use isset()?
  5. I will try to be short. I am getting a Notice about the code below. " Notice: Undefined offset: 1 " it refers to the last line of the code below. That code worked for 3 years and I changed nothing, now for some reason I am getting the notice. Can you help? $total_type=($row ['type1'] ); $typeChunks = (explode("|", $total_type,2)); $type2 = ($typeChunks[0]); $type_link = ($typeChunks[1]);
  6. Thank you!! I have been the most of two days trying to figure that out. Now to incorporate it into the form on the actual page. Below is the code that worked. $i = 1; // Initialize $i outside the loop echo '<table class="one" width="500" border="0" cellpadding="0" cellspacing="0" align="center">'; $resource = $db->query("SELECT * FROM `outside_levy` WHERE `budget_year` = '".$budget_year2."' AND `department` != '".$blank."' AND `levy_type` != '".$tax_credit."' AND `levy_type` != '".$tax_credit_ag."' ORDER BY `rank` ASC, `levy_type` ASC, `department` ASC LIMIT 0, 40"); while ($row = $resource->fetch_assoc() ) { echo '<tr><td width="90%">'; echo '<div class="levy2">'; echo $i++; echo '<b>'; $tax=number_format(($row ['levy'] )*$value2, 2); echo ' &nbsp; '; echo ($row ['department'] ); echo '</b></div>'; echo '</td><td width="10%"><div class="rightblack">'; echo $tax; echo '</div>'; echo '</td></tr>'; }
  7. I am updating a website to php7 from php5. The project was going well until I come to this page. The page actually uses a form to transfer information to the next page with the checkboxs numbered as ($i+1). The code below in not the form but I "think" that if I can get that code to work I can make the form work. I need to place 1, 2, 3, etc in the result from the php7. when I leave out (for ($i=0; $i < $match_results; $i++)) and (echo ($i+1);) the rest works fine but my form boxes are not numbered so will not transfer to the next page. The link below is the page that works with php5 with the checkbox form on the right. http://www.sheridancountyne.com/levy_page.php?year=2017&amp;value=56000 The below code works with php5 <html> <body> <?php require ("$path/require/connect.php"); $budget_year2=("2017"); $tax_credit=("Tax Credit"); $tax_credit_ag=("Tax Credit Ag"); $show=("show"); $base=("Base"); $value2=("50000"); echo '<table class="one" width="500" border="0" cellpadding="0" cellspacing="0" align="center">'; $query= ("SELECT * FROM `outside_levy` WHERE `budget_year` = '".$budget_year2."' AND `department` != '".$blank."' AND `levy_type` != '".$tax_credit."' AND `levy_type` != '".$tax_credit_ag."' ORDER BY `rank` ASC, `levy_type` ASC, `department` ASC LIMIT 0, 40"); $query_results=mysql_query($query); $match_results=mysql_num_rows($query_results); for ($i=0; $i < $match_results; $i++) { $row=mysql_fetch_array($query_results); echo '<tr><td width="90%">'; echo '<div class="levy2"><b>'; $tax=number_format(($row ['levy'] )*$value2, 2); echo ($i+1); echo ' &nbsp; '; echo ($row ['department'] ); echo '</b></div>'; echo '</td><td width="10%"><div class="rightblack">'; echo $tax; echo '</div>'; echo '</td></tr>'; } echo '</table>'; mysql_close($db); ?> </body> </html> I need to place the code for ($i=0; $i < $match_results; $i++) and echo ($i+1); in the new code for php7 below. <html> <body> <?php require ("$path/require/connectphp7.php"); $budget_year2=("2017"); $tax_credit=("Tax Credit"); $tax_credit_ag=("Tax Credit Ag"); $show=("show"); $base=("Base"); $value2=("50000"); echo '<table class="one" width="500" border="0" cellpadding="0" cellspacing="0" align="center">'; $resource = $db->query("SELECT * FROM `outside_levy` WHERE `budget_year` = '".$budget_year2."' AND `department` != '".$blank."' AND `levy_type` != '".$tax_credit."' AND `levy_type` != '".$tax_credit_ag."' ORDER BY `rank` ASC, `levy_type` ASC, `department` ASC LIMIT 0, 40"); while ($row = $resource->fetch_assoc() ) for ($i=0; $i < $match_results; $i++) // this does not work here in php7 how do I write a code that will work with (Si+1) below { echo '<tr><td width="90%">'; echo '<div class="levy2"><b>'; $tax=number_format(($row ['levy'] )*$value2, 2); echo ($i+1); //this is the part that will not work in php7 echo ' &nbsp; '; echo ($row ['department'] ); echo '</b></div>'; echo '</td><td width="10%"><div class="rightblack">'; echo $tax; echo '</div>'; echo '</td></tr>'; } echo '</table>'; $db->close(); ?> </body> </html>
  8. I have a website that has worked fine for several years. It uses php and a mysql data base. I can still make changes to the data base, but have a hard time getting the new text to show up. It is changed in the data base but the browser insists on showing a cached copy. In the past it worked fine. Don't know what changed. I also use a cookie set by a user name and password and now when I click on the log out function, I need to refresh the log out page before it logs me out. I have looked for a method to disable the cache but nothing I have found works. The site is on a Windows server, not by my choice. Any ideas?
  9. Thank you, I believe I can work with that and it will do just what I want it to do. JackW
  10. Thanks, I may be able to make that work. What I really need is just a simple piece of code that does the link part provided in the rich text editor. That may well not be something that is available. JackW
  11. I am developing a website where my client can update the text using simple forms. I have developed several such site using php and a MySQL database. My current client wants to have the ability to add links within the text without typing the full link code. The form I am using to post this question has the function I need. A box pops up where one can put in the url and form a link. Can someone tell me how to create that function for my page?
  12. I have been trying for days to write a code that will upload a picture to my server after renaming it, verifying that it is a picture and not oversized, then add a link to my data base. What I have put together works fine when all requirements are met, however if I substitute a file that is not a picture (example .txt) page 2 either locks up as a blank page or uploads the incorrect file to the site. No error message of any kind. What am I doing wrong? Your help will be greatly appreciated. Here is my code:Page 1<html><body><form action="add6.php" method="post"enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file" /> <br /><input type="submit" name="submit" value="Upload Picture" /></form></body></html>Page 2<html><body><?php if (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file"]["type"] == "image/pjpeg")|| ($_FILES["file"]["type"] == "image/jpg")&& ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else {//This function separates the extension from the rest of the file name and returns it function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to our file $ext = findexts ($_FILES['file']['name']) ;//This line assigns a random number to a variable. You could also use a timestamp here if you prefer. $ran = rand () ;//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.$ran2 = $ran.".";//This assigns the subdirectory you want to save into... make sure it exists!$target = "/My_site_info/uploads/";//This combines the directory, the random file name, and the extension$target = $target . $ran2.$ext; $image = $ran2.$ext;//Writes the photo to the server if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) {echo "The file has been uploaded as ".$ran2.$ext;echo '<form action="putin.php" method="POST"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br> <input type="hidden" name="picture"value="';echo$image;echo '">' ;echo'<input type="submit" value="Submit"> </form>';} else{echo "Sorry, there was a problem uploading your file."; } }}?> </body></html>Page 3<html><body><?php$username="Myusername";$password="mypasswordy";$database="mydatabase";//This gets all the other information from the form $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=$_POST['picture']; // Connects to your Database @$db = mysql_pconnect('myinfo,'mydatabase','mypasswordy');mysql_select_db('mydatabase') or die( "Unable to select database");//Writes the information to the database {mysql_query("INSERT INTO `mytable` VALUES (NULL,'$name', '$email', '$phone', '$pic')");}$results=mysql_query($query);{echo 'Thank you for Submitting your information;}mysql_close($db);?></body></html>
  13. Wow, that was fast.Thank you. I will get to work on it. I just wasn’t sure if a home page url index page had to have a .html extension.
  14. I am building a web site where I need the newest listings from MySQL data base shown on the home page.If I name the home page index.php, it works fine on my browser. Can someone tell me if that will work on all browsers? If not, what can I do to get it to bring up the page that has the data base information when someone clicks on my homepage url?
  15. I have a row in my data base that contains information like 10 Oct. It is all in one row and I need to echo just the three letters in one area and all of it in another. I am sure there is a way but can't seem to remember where I found it.Your help will be appreciated.Jack
×
×
  • Create New...