Everything posted by arjay
-
How important is i 6 compatibility nowadays.
I've got an old PIII PC with two old 40 Gb hard disks. Cost me little or nothing - thrown away by a friend plus a few bits and pieces from my stock of the same. I dual-boot a copy of win 2000 on each HDD with ie6 on one and ie 7 on another. Doesn't help with the specific coding issue, but at least you can see how your sites look as you work. Oh, of course I have Firefox on both disks for real work. Got to be better than logging onto some site or other each time you want to preview changes!
-
php for array value on one page to be search variable on next?
Thanks for the advice. I am quite happy with the GET procedure - it is just that I am only learning about php at the moment, so always open to advice and suggestions about the best way to do things. RJ
-
php for array value on one page to be search variable on next?
I'm open to suggestions as to a simpler or more elegant or whatever method. In a nutshell, this is what I want to do. I have a page of dogs photos displayed together with their names on, say, the "dogs for rehousing" page. These are produced via a database query when a user clicks on a link to that page. These images/names are displayed as clickable links. A person wanting to know more about a particular dog will click on that dog's image/name. This triggers a fuller search of the database for more info on the dog and it gets displayed on another page. There are no forms involved anywhere... Is that enough info? RJ
-
php for array value on one page to be search variable on next?
OK - I've cracked this problem The line for the link on my Page 1 (using my variables) should look like: echo "<a href=\"http://localhost/xampp/sosoldsite/dogfactstemplate.php?name=$name\"> <p class=\"name\">".$name."</p>\t\r"; And the GET statement on my Page 2 looks like: $name=$_GET['name']; Then the query includes this variable, so: $result = mysql_query("SELECT category, name, weight, height, age, gender, colour, breed, history, disposition, photo1, photo2 FROM sosanimals WHERE type= 'dog' AND name='$name' ") or die(mysql_error()); This seems to work fine. Many thanks to Elite for the generic code - just took a while to figure out how to translate it
-
php for array value on one page to be search variable on next?
Hi Elite. Well, the problem with only half understanding your advice is I get zero output. The problem is with trying to change your code to fit my variables. Perhaps if I give a bit more detail you could help contextualise your code for my situation? On my "Page1" I have the line: echo "<a href=\"http://localhost/xampp/sosoldsite/dogfactstemplate.php\"> <p class=\"name\">".$name."</p>\t\r"; Clicking the name will take the user to a page where I want to display more information about a particular dog. The variable I want to carry over to the next page is the one created by the line: $name = $results_array["name"]; name is the field name in my table for the dog's name and is the variable I want to carry over to Page 2 and search with the line: $result = mysql_query("SELECT category, name, weight, height, age, gender, colour, breed, history, disposition, photo1, photo2 FROM sosanimals WHERE type= 'dog' ") or die(mysql_error()); I'll carry on trying to change these lines to produce the right output, but if you have a moment to help convert your code to my variables I would be very grateful Cheers
-
php for array value on one page to be search variable on next?
Hey - thanks Elite for the quick response. I am a bit of a noob at php (OK with html and css) so it may take me a bit to understand exactly what has to go where. But give it a go I will
-
php for array value on one page to be search variable on next?
Hi all, I am helping an animal charity to redesign their website and to move to a database-driven set-up. I have a database with details on 170 dogs the charity is trying to get rehoused. Thanks to help from snowyswebsolutions and dddougal in this forum I have got to a position where I can display the name and photo of each dog as a clickable link on a page. The idea is for the visitor to click on a dog they like and be taken to a second page where they get all the facts and figures on that dog. Obviously, I don't want to have 170 html pages each with data on a different dog. What I need is a way for the name of a dog (or the name of its photo) stored in an array on page 1 to become one of the search criteria in a database search on page 2. Page 2 is just a template with a table set up up to echo that dog's full information. The relevant bit of code on Page 1 is: // sending query $results = mysql_query("SELECT * FROM $table WHERE type= 'dog' AND category = 'small' ORDER BY name"); if (!$results) { die("Query to show fields from table failed"); } while($results_array = mysql_fetch_array($results)) { $id = $results_array["id"]; $image = $results_array["photo1"]; $name = $results_array["name"]; echo "<div class=\"dog_box\">\r"; echo "\n"; echo "<p class=\"name\">".$name."</p>\t\r"; echo "\n"; echo "<a href=\"http://localhost/xampp/sosoldsite/dogfactstemplate.php\"> <p class=\"dog_img\"> ". $image ." </p></a>\t\r"; echo "\n\t"; echo "</div>"; } echo "<div class=\"clear\"></div>"; Thus, clicking on any of the photos takes the user to a page called dogfactstemplate.php. At the moment, on that page I have the following php - really just to make sure a search and table all work. The query is not correct, because it echoes ALL the dogs in the relevant category, not just the one the viewer wants to see: // sending query $result = mysql_query("SELECT category, name, weight, height, age, gender, colour, breed, history, disposition, photo1, photo2 FROM sosanimals WHERE type= 'dog' AND category='small' ") or die(mysql_error()); $fields_num = mysql_num_fields($result); echo "<table width='500px' background-color:transparent; cellpadding=5 > <tr>"; echo "<td width='200px' align=left <font color=#000000 size=3> Basics</font></td>"; echo "<td width='100px' align=left <font color=#000000 size=3> History</font></td>"; echo "<td width='200px' align=center <font color=#000000 size=3> </font></td>"; echo "</tr>\n"; // printing table rows $id = "id"; $category = "category"; $name = "name"; $weight = "weight"; $height = "height"; $age = "age"; $gender = "gender"; $colour = "colour"; $breed = "breed"; $history = "history"; $disposition = "disposition"; $photo1 = "photo1"; $photo2 = "photo2"; while($row = mysql_fetch_array($result)) { echo "<td align=left valign=top> Size: $row[$category]<br><br> Weight: $row[$weight]<br><br> Height: $row[$height]<br><br> Age: $row[$age]<br><br> Gender: $row[$gender]<br><br> Colour: $row[$colour]<br><br> Breed: $row[$breed]<br></td>"; echo "<td align=left valign=top> $row[$history] <br><br> $row[$disposition] <br> "; echo "<td align=left valign=top> $row[$photo1] </td>"; echo "</tr>"; } mysql_free_result($result); ?> </table> Can anyone help me to amend the query on the second page so that, for example, if the viewer clicks on an image called "pluto.jpg" on the first page, that becomes one of the search criteria to bring up Pluto's facts on page 2? TIA for any help. RJ
-
help plse to echo table in html from database
Thanks for the detailed explanation - I reckon I got it now I did look up lightbox. I found it interesting but had to park it as something to be read up on when I have a moment. I am learning so much new stuff at the moment, it is a bit of a struggle to understand everything. I removed the lightbox content to see if I could simplify the line in order to find the syntax error - that's all. It will go back in, now dddougal helped me find the error. Thanks to you for the original code. RJ
-
help plse to echo table in html from database
Thanks so much - that did it
-
help plse to echo table in html from database
Just for the sake of completeness the relevant bit of code looks like this: // sending query $results = mysql_query("SELECT * FROM $table WHERE type= 'dog' AND category = 'small' ORDER BY name"); if (!$results) { die("Query to show fields from table failed"); } while($results_array = mysql_fetch_array($results)) { $id = $results_array["id"]; $image = $results_array["photo1"]; $name = $results_array["name"]; $weight = $results_array["weight"]; $dog_type = $results_array["category"]; echo "<div class=\"dog_box\">\r"; echo "\n"; echo " <p class=\"name\">".$name."</p>\t\r"; echo "\n"; echo " <p class=\"dog_type\">".$dog_type."</p>\t\r"; echo "\n\t"; echo " <p class=\"weight\">".$weight."</p>\t\r"; echo "\n\t"; echo "<a href=\"http://localhost/xampp/sosoldsite/dogfactspage.php\" ><img src=\".$image.\" ></a>\t\r"; echo "\n\t"; echo "</div>"; } echo "<div class=\"clear\"></div>";
-
help plse to echo table in html from database
snowswebsolutions First, sincere apologies for not replying sooner. For some strange reason, I only get a notification of a reply by email about one in three of my posts. I saw no email so just checked back on the off-chance and there was your superb reply. So, second, many thanks for the code you supplied. I am a bit of a newbie at php, so it took a while to figure out what you had set out (I like to know why something is coded the way it is, rather than copying it blindly). I have got everything to work - obviously changing a few field-names along the way. I am pretty ok at css so no probs there. I must admit, I have struggled to understand the purpose of all the bits of the line: echo "<a href=\"images/for_web/dogs/large/".$name.".jpg\" rel=\"lightbox\" title=\"Name: ".$name." | Weight: ".$weight."\"><img src=\"".$image."\" width=\"200\" height=\"149\" class=\"dog_img\" ></a>\t\r"; The backslashes for each double quote get very confusing. The images are stored in my database in this way: <img src="http://localhost/xampp/sosoldsite/smalldogsphotos/marlene.jpg" height=90" width="93"> (I am still running things on a local server during design). So I tried replacing your line with the simple: echo " $image "; and that comes out fine in the sense that I can now get 5 pictures across the available space on my page, each one headed by whatever field data I want - brilliant!! Of course this does not make the images clickable links which is obviously the purpose of your line of code. However, is there a syntax error in your line? It prints the content of the end of the line rather than an image - something like: . I have tried reducing the complexity of your line by removing the references to lightbox etc. This leaves: echo "<a href=\"http://localhost/xampp/sosoldsite/dogfactspage.php\" ><img src=\".$image.\" ></a>\t\r"; but this still produces an error, printing instead of any images. I can't for the life of me see what it is but perhaps another pair of eyes could help here? Thanks again for all your help. RJ
-
help plse to echo table in html from database
Hi all, I am helping an animal charity to redesign their website and to move to a database-driven set-up. I have a database with details on 170 dogs the charity is trying to get rehoused. If a visitor clicks on a page about dogs available to be rehoused, the page should display all the dogs in that category (e.g. small, medium, or large) I have got the DB set up ok and can display details of the animals but not in the layout I want. For example, there might be 70 small dogs whose names and photos I want to have displayed on a specific page. Currently I just have a simple two-column table that echos the name and picture of each dog as a new row. This is fine except I have a very long page with 70 dogs names and pictures running down it. The code I have got together so far is: // sending query $result = mysql_query("SELECT name, photo1 FROM sosanimals WHERE type= 'dog' AND category = 'small' "); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); // printing table rows $name = "name"; $photo1 = "photo1"; while($row = mysql_fetch_array($result)) { echo "<TABLE width=250px>"; echo "<TR> <TD width=150px>$row[$name] <br> $row[$photo1] </TD></TR>"; echo "</TABLE>"; } What I would like to do is have the page show each dog's name with its photo beneath it across the page - there is room for 4-5 photos - and then a new row of 4-5 photos/names and so on until all the dogs in that category have been exhausted. In the case above, that would be, say, about 14 rows with 5 dogs in each. Hope this is clear - can someone help me with the code for a table that would do this? Many many thanks RJ
-
php - stop echo of empty mysql cells?
Thanks for the examples everyone. I'll keep them in my files for when I get to that stage in my learning about php/mysql.
-
php - stop echo of empty mysql cells?
Avera [or SniderDK if it comes to that] Could either of you just amplify this for me ("also the code could work directly off the $row array and doesnt need to make a $address array"). I am keen to understand this area and arrays are next on the list for my studies! This is what I used in my php from your suggestion: // Build an address array. $address = array(); $address[] = $row['address1']; $address[] = $row['address2']; $address[] = $row['address3']; $address[] = $row['town']; $address[] = $row['postcode']; $address[] = $row['province']; $address[] = $row['phoneland']; $address[] = $row['phonemob']; $address[] = $row['fax']; // now we have an array with our address in it, let's do some magical stuff $addrblock = ''; foreach($address as $k=>$v) { if (isset($v) && !empty($v)) $addrblock .= trim($v) . '<br/>'; } echo "<td class='sr_number'>$addrblock", '<br>'; Note I have made the changes and removed the redundant line as per SniderDK's suggestion. Thanks to both of you. I think it is marvellous that experts like yourselves are prepared to give so generously of your time to people you don't even know and are unlikely to ever meet. Luckily I am a retired psychologist and am designing a database-driven website just as a way of teaching myself something new. Not sure I would want to do this for a living What a great forum this is.
-
php - stop echo of empty mysql cells?
Thanks for clarifying this for me. Just so I understand - how would your code look different with this new knowledge? Here is a clip of it: if(isset($row[$address2])){ echo $row[$address2].'<br>'; }else{ echo 'None'; } Cheers RJ
-
php - stop echo of empty mysql cells?
Avera - sorry I posted my latest without reading yours. I am going to have a go with your suggestion (when i have figured out what it all means! I like to try and understand if at all possible rather than just knock it out blindly...) EDIT: Thanks for the reminder about single quotes where it is not a variable. MY BAD. I did not explain that the code I am using is to echo the results of a search of the database to a "Results Page". The fields are defined as variables in another file that is called as part of the search exercise - hence no quotes. Now - good news. I have tried your code by just constructing a new php page and it ran fine. I then cut and pasted just this block from your code: // Build an address array. $address = array(); $address[] = $row['address1']; $address[] = $row['address2']; $address[] = $row['address3']; $address[] = $row['town']; $address[] = $row['province']; $address[] = $row['phoneland']; $address[] = $row['phonemob']; $address[] = $row['fax']; // now we have an array with our address in it, let's do some magical stuff $addrblock = ''; foreach($address as $k=>$v) { if (isset($v) && !empty($v)) $addrblock .= trim($v) . '|'; } $addrblock = str_replace('|', '<br />', $addrblock); echo $addrblock; into my Results Page. The echo process now works brilliantly - no more blank lines. I have just about figured out how you did it. You are a very clever chap. Hat's off to you. And many thanks of course. RJ BTW - if the other posters want me to try variations of their scripts in order to track down why they did not work - I'll help of course. But I now have a solution that works so all is well for me.
-
php - stop echo of empty mysql cells?
OK - I have tried the first two suggested methods. Neither worked in the sense that even if a cell had no entry, echo still produced a blank line. Initially this suggested me that there was something in the database definition for that field which made the query think there was data in that field. EDIT: This seems unlikely given that Avera's suggested code does work (see later post). Right, first, the first suggested method. Here is what I tried: $adline1 = "$row[$address1] <br>"; $adline2 = "$row[$address2] <br>"; $adline3 = "$row[$address3] <br>"; if ($adline1 != '') { echo "<td class='sr_number'>$adline1"; }else{echo "NONE";} if ($adline2 != '') { echo "$adline2"; }else{echo "NONE";} if ($adline3 != '') { echo "$adline3"; }else{echo "NONE";} </td> Note that, just to be sure, I added an else statement which I presume should echo "None" if the cell was empty. This was not the case. Cells with data were echoed correctly, but empty cells gave a blank line. The word None was not echoed if a cell was empty. Now - the second suggested code: echo "<td class='sr_number'>"; if(isset($row[$address1])){ echo $row[$address1].'<br>'; }else{ echo 'None'; } if(isset($row[$address2])){ echo $row[$address2].'<br>'; }else{ echo 'None'; } if(isset($row[$address3])){ echo $row[$address3].'<br>'; }else{ echo 'None'; } if(isset($row[$town])){ echo $row[$town].'<br>'; }else{ echo 'None'; } if(isset($row[$postcode])){ echo $row[$postcode].'<br>'; }else{ echo 'None'; } if(isset($row[$province])){ echo $row[$province].'<br>'; }else{ echo 'None'; } if(isset($row[$phoneland])){ echo $row[$phoneland].'<br>'; }else{ echo 'None'; } if(isset($row[$phonemob])){ echo $row[$phonemob].'<br>'; }else{ echo 'None'; } if(isset($row[$fax])){ echo $row[$fax].'<br>'; }else{ echo 'None'; } </td> This echoes the data correctly where there are entries in the fields but still gives a blank line rather than "None" if a cell is empty. The setup for the relevant variables follow this format: Field: address1 Type: varchar(255) Default: None Null: (off - i.e. unchecked) I have tried choosing null but same result. I have tried entering a new row manually (the data would normally come by way of a processed form) and deliberately leaving one of the address lines blank - still get blank lines and the word "None" never appears. Not sure where to go from here. Can anyone help me troubleshoot this one? Many thanks.
-
php - stop echo of empty mysql cells?
many thanks to both of you. I am only a newbie at php, so it may take me a while to figure out your code. But get there I will!! I'll report back when I make some progress. Regards RJ
-
php - stop echo of empty mysql cells?
Hi all I have the results of a search of a business directory database echo to a table in a results page. This sort of thing: echo "<td class='sr_number'>$row[$address1]<br> $row[$address2] <br> $row[$address3] <br> $row[$town] <br> $row[$postcode] <br> $row[$province] <br> $row[$phoneland] <br> $row[$phonemob] <br> $row[$fax] <br>" The problem is, the table looks untidy if the business address has only one line instead of three, or they don't have a fax number etc. The echo statement produces empty lines that look ugly. Is there a way that I can have the statement only echo where there is actual content in a cell? I have searched a lot but maybe using the wrong words. Apologies if it is a common request.
-
javascript onclick/ondblclick not working properly for images
Brilliant - thanks for spotting the typo. I couldn't see the wood for the trees! I'll look at Lightbox - muchas gracias for the help RJ EDIT: Can anyone help how to mark this up as SOLVED? Cheers
-
javascript onclick/ondblclick not working properly for images
skidz - thanks for the reply. I'll certainly give this a go. I will have to find some info on the code itself, as I am a complete noob when it comes to js. The snippet I am using was a straight lift from code I found on the internet. Thanks again.
-
javascript onclick/ondblclick not working properly for images
Hi all On our classic car club website we have a writeup each month of the last event. The text includes photos that can be enlarged by clicking on them. A double click then restores the original photo. This is done by this JS code: <img src="/non_gallery_photos/feb2009run/eco_hotel_start1.jpg" width=300 height=180 hspace=10 vspace=15 align=right alt="Eco Hotel Start" onclick="src='/non_gallery_photos/feb2009run/eco_hotel_start1.jpg'; width=500; height=280; hspace=10; vspace=15 "; ondblclick="src='/non_gallery_photos/feb2009run/eco_hotel_start.jpg1'; width=300; height=180; hspace=10; vspace=15 " /> However, each month, one out of three or four photos is "lazy" and won't return to the original state after being enlarged - a different one in a different location each month. It just shows the space and not the image - just the Alt tag. Anyone viewing the site has to hit F5 to refresh the page. When we write the story I usually cut and paste the above code from place to place and just change the align tags depending on the layout, so there shouldn't be any typos or whatever. Please have a look if you would at this link of the offending page: Sol Classic Car Club/Last Event where the first image is the problem. Any help really appreciated. Many thanks RJ
-
Website search facility
Elite You generously said you would help me construct a script to provide local search facilities for a website I am developing. I was hoping that i could take you upon it! I have now setup a local server and have xampp running ok (Mepis Linux). I have set up a sample mysql database that contains fields for a local business directory ( business name, contact details, services offered, etc etc). I have entered some sample data using phpmyadmin. [ I have a sidebar menu that provides the main categories, but obviously i will need a facility for users to search the site.] Can you point me in the right direction? Thanks Richard BTW - I had a look at your site (I am interested because I used to keep tropical fish). However, the site does not appear to display correctly in Linux Firefox 3.0.3 I have taken a snapshot of how the display looks - if you want me to send it to you somewhere I will.
-
Website search facility
Thanks - I'll take you up on it. In the meantime, it doesn't solve my problem. Surely there must be software somewhere that can be installed on my PC to index/search web pages? I'll have a look elsewhere and see what I can find. RJ
-
Website search facility
Thanks for this info - it looks interesting, for when I host my site. However, at the moment, I am still looking for something I can use on my own PC and test, rather than something that is hosted on someone else's server. BTW - all the data I want indexed and searchable at the moment is just in html pages. I am still looking at the possibility of converting the data to database format. Thanks anyway.