Forum Moderators: mack

Message Too Old, No Replies

retrieving all database fields instead of selected ones

         

pierjean

7:16 pm on Dec 6, 2014 (gmt 0)

10+ Year Member



Hello.
I am new to php. Although I am 70 years old, I need baby steps helping me finish this. Not to be completely stupid, I did some homework learning everyday 10 hours a day for the last month or so but my time is limited so I finally decided to seek some help from a helpful hand.

mysql is version 5.5.40 I am using wordpress that I had to learn in the process.
[removed url]

I created a form for members registration to feed the database and this is workling.
[removed url]

In my home page I created a search form for visitors to retrieve selected members according to their location (drop-down menu with available zip codes) and specialties (Check-box)

To simplify and avoid being confused during my learning, ma database shows only 2 members
on the php form I only mentioned 2 zip codes and 2 specialties when in reality each member (about 20) have 2 to 5 specialties (out of 10) and cover an area of 6 to 8 zip codes.(out of 65.)

I am getting close but cannot find what I am looking for to finish this.
I am like a dog trying to bite his tail, but not being one I do not have this luxury! :)
!(baby steps please, or walker appreciated !)

Thanks in advance.

in short here are my problems:

1) from the search form on the left column, whatever pet service a visitor choose in their own zip code, or even no selection at all, the result gives all members in the database regardless of their specialty or zip code covered..

( also, do I have to place each 60 zip code on a different field in the database and is there a way to avoid mentioning them again in separate line in the php ?)
ie:echo $row[zipcode -89109]."";etc... 60 times or so....
that is king of overwhelming!



2) The search results are showing in the same column as the form that is too narrow. I am trying to show the results in the "result page"
[removed url]
I really like to keep this search form on the home page left column, so it is available at first glance.


3) finally, results are displaying in one block,(it took me 2 weeks to realize this exploit !YES ! but it is not very pretty or easy to read. I found out how to make a title but cannot separate the words. The member's bio (with eventual picture) will be more complete so It needs to be separated paragraph.


-----------------------------------
search.HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/></head>
<body bgcolor="#FFFFFF">
<center>
<script type="text/javascript" src="swfobject.js"></script><div id="CC8404954">Form Object</div><script
type="text/javascript">var so = new SWFObject("search.swf", "search.xml", "275", "546", "7,0,0,0", "#ffffff");so.addParam("classid",
"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");so.addParam("quality", "high");so.addParam("scale", "noscale");so.addParam("salign",
"lt");so.addParam("FlashVars", "xmlfile=search.xml&w=275&h=546");so.write("CC8404954");</script>
</center>
</body>
</html>

--------------------------

search.php

<?php
$db = mysql_connect("localhost","pierjean","*********");
if (!$db) {
die("Database connection failed miserably: " . mysql_error());
}


$db_select = mysql_select_db("snapps",$db);
if (!$db_select) {
die("Database selection also failed miserably: " . mysql_error());
}
?>


<?php
$db = mysql_connect("localhost","pierjean","********");
if (!$db) {
die("Database connection failed miserably: " . mysql_error());
}




<html>
<head>
<title>members</title>
</head>
<body>


IN CONSTRUCTION. TRY OUT ONLY
please try again later.than you


<div class="cssstyle">
<?php

$result = mysql_query("SELECT * FROM members", $db);
if (!$result) {
die("Database query failed: " . mysql_error());
}


while ($row = mysql_fetch_array($result)) {
echo "<h2>";
echo $row[company]."";
echo "</h2>";
echo "<p>";
echo $row[firstname]."";
echo $row[lastname]."";
echo $row[phone]."";
echo $row[website-url]."";
echo $row[Email]."";
echo $row[Bio]."";
echo $row[11]."subcategory-Exotics";
echo $row[zipcode-89102]."";
echo $row[zipcode -89109]."";
echo $row[Overnight-stay]."";

echo "</p>";
}
?>
</div>
</body>
</html>

<?php


mysql_close($db);
?>

--------------------------------

MY FORM
search.xml


<?xml version="1.0" encoding="UTF-8"?>

<form url="search.php"
window="_self"
method="POST"
fontname="MS Sans Serif"
width="256"
height="546"
bkcolor="0xFAF9C0"
transparent="f"
fontcolor="0x000000"
outlinecolor="0x008000"
themecolor="0xFFFF99"
fontcolor2="#000000"
bkcolor2="#FFFFFF"
includeresults="false"
emailuser="true"
verifymessage="The E-Mail address you entered does not match !"
reqmessage="One or More Fields are Required !"
invalidemailmsg="does not appear to be a valid e-mail address. Would you like to change it?"
transition="0"
autoresponseincluderesults="t"
autoresponseaddtotop="f"
usephp="true"
disableclicktoactiveprompt="true"
extensions="*.txt;*.gif;*.jpg;*.jpeg;*.zip;*.doc;*.png;*.pdf;*.rtf;*.html;*.docx;*.xslx"
>

<hidden
name="subject"
value="snapps form"
></hidden>

<image
image="left_border.png"
x="25"
y="25"
></image>

<image
image="right_border.png"
x="368"
y="25"
></image>

<image
image="dog walking.jpg"
x="150"
y="900"
></image>

<textinput
name="my-zip-code"
x="12"
y="72"
w="110"
h="22"
initvalue=""
maxchars="25"
bkcolor="0xFFFFFF"
fontname="Arial"
fontcolor="0x000000"
editable="true"
>
</textinput>

<combobox
name="zipcode"
x="12"
y="120"
bkcolor="0xFFFFFF"
fontcolor="0x000000"
isemail="false"
w="130"
h="20">
<item name="scroll down"></item>
<item name="89002"></item>
<item name="89005"></item>
<item name="89011"></item>
<item name="89012"></item>
<item name="89014"></item>
<item name="89015"></item>
<item name="89030"></item>
<item name="89031"></item>
<item name="89032"></item>
<item name="89033"></item>
<item name="89044"></item>
<item name="89052"></item>
<item name="89074"></item>
<item name="89081"></item>
<item name="89084"></item>
<item name="89085"></item>
<item name="89086"></item>
<item name="89087"></item>
<item name="89101"></item>
<item name="89102"></item>
<item name="89103"></item>
<item name="89104"></item>
<item name="89106"></item>
<item name="89107"></item>
<item name="89108"></item>
<item name="89109"></item>
<item name="89110"></item>
<item name="89113"></item>
<item name="89115"></item>
<item name="89117"></item>
<item name="89118,"></item>
<item name="89119"></item>
<item name="89120"></item>
<item name="89121"></item>
<item name="89122"></item>
<item name="89123"></item>
<item name="89124"></item>
<item name="89128"></item>
<item name="89129"></item>
<item name="89130"></item>
<item name="89131"></item>
<item name="89134"></item>
<item name="89135"></item>
<item name="89138"></item>
<item name="89139"></item>
<item name="89141"></item>
<item name="89142,"></item>
<item name="89143,"></item>
<item name="98144"></item>
<item name="89145"></item>
<item name="89146"></item>
<item name="89147"></item>
<item name="89148"></item>
<item name="89149"></item>
<item name="89156"></item>
<item name="89161"></item>
<item name="89165"></item>
<item name="89166"></item>
<item name="89169"></item>
<item name="89178"></item>
<item name="89179,"></item>
<item name="89183"></item>
</combobox>

<submitbutton
name="Submit Button"
x="156"
y="444"
w="73"
h="40"
label="Submit"
fontname="Arial"
fontcolor="0x003300"
fontbold="bold"
fontsize="18"
></submitbutton>

<browsebutton
name="Upload File Button"
x="25"
y="975"
w="155"
h="45"
label="SUBMIT"
fontname="Arial"
fontcolor="0x003300"
image="submitcircularroundlarge.png"
fontbold="bold"
fontsize="12"
></browsebutton>

<checkbox
name="specialties"
x="132"
y="252"
w="90"
h="19"
label="House Sitting"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="12"
y="180"
w="108"
h="19"
label="Animal Massage"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="132"
y="228"
w="92"
h="19"
label="Hospice Care"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="132"
y="276"
w="94"
h="19"
label="Overnight Stay"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="132"
y="180"
w="70"
h="19"
label="Dog Reiki"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="12"
y="252"
w="82"
h="19"
label="Hotel Sitting"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="132"
y="204"
w="86"
h="19"
label="Dog Walking"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="12"
y="204"
w="87"
h="19"
label="Dog Training"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="12"
y="228"
w="69"
h="19"
label="Dog Yoga"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="subcategory"
x="96"
y="324"
w="55"
h="19"
label="Exotics"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="specialties"
x="12"
y="276"
w="94"
h="19"
label="Vet Technician"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<checkbox
name="subcategory"
x="156"
y="324"
w="92"
h="19"
label="Farm Animals"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<label
name="My Text 6"
x="300"
y="75"
w="7"
h="15"
text=""
fontname="Times New Roman"
fontcolor="0x352C20"
fontsize="13"
></label>

<label
name="My Text 11"
x="12"
y="156"
w="76"
h="19"
text="Specialties"
fontbold="bold"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="16"
></label>

<label
name="My Text 12"
x="12"
y="300"
w="78"
h="19"
text="Pet Sitting:"
fontbold="bold"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="16"
></label>

<captcha
name="My Captcha 1"
x="12"
y="420"
w="133"
h="101"
text="Enter Key Here:"
fnt="Arial"
fntclr="0x000000"
fntbold="t"
fntsize="13"
bkbdrcolor="0x000000"
bkfillclr="0xFFFFFF"
bkdobdr="t"
bkbdrsolid="t"
bkdobk="t"
bkfillalpha="100"
message="Incorrect key!"
></captcha>

<label
name="My Text 2"
x="12"
y="48"
w="152"
h="19"
text="Enter your zip code here"
fontname="Times New Roman"
fontcolor="0x000000"
fontsize="16"
></label>

<label
name="My Text 3"
x="12"
y="96"
w="200"
h="19"
text="or check nearest zip code below"
fontname="Times New Roman"
fontcolor="0x000000"
fontsize="16"
></label>

<label
name="My Text 8"
x="60"
y="372"
w="82"
h="15"
text="702-655-7397"
fontbold="bold"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="13"
></label>

<checkbox
name="subcategory"
x="12"
y="324"
w="76"
h="19"
label="Dogs-Cats"
labelPos="right"
value="checked"
fontsize="12"
fontname="Arial"
fontcolor="0x000000"
></checkbox>

<label
name="My Text 4"
x="12"
y="348"
w="189"
h="15"
text="For services not listed please call"
fontitalic="italic"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="13"
></label>

<label
name="My Text 5"
x="12"
y="396"
w="197"
h="15"
text="or email us [removed email address]"
fontitalic="italic"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="13"
></label>

<label
name="My Text 1"
x="60"
y="0"
w="130"
h="19"
text="Search for the best"
fontbold="bold"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="16"
></label>

<label
name="My Text 7"
x="24"
y="24"
w="213"
h="19"
text="Pet Services in Las Vegas Area"
fontbold="bold"
fontname="Times New Roman"
fontcolor="0x003300"
fontsize="16"
></label>

<hiddenfield
name="My Hidden Field"
value=""
></hiddenfield>

</form>

[edited by: brotherhood_of_LAN at 9:36 pm (utc) on Dec 6, 2014]
[edit reason] see my post below [/edit]

brotherhood of LAN

9:49 pm on Dec 6, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to the forums pierjean,

Firstly, congrats on your persistence to learn and put the hours in, and I think you're right in coming to ask fellow coders... forums and dialogue can really complement learning you can achieve on your own.

I've removed the links in your post as per the terms of service of this forum, as links eventually break and that limits the usefulness of the discussion for future viewers.

It might be worth me pointing out the distinction between client side (HTML/CSS) and server side (PHP/MySQL) in your questions, as it can help to break down the questions into smaller ones, and may who have client side experience may not be able to comprehend the server side, and vice versa. Usually for client side problems you don't need to know about server side technologies, and vice versa.

For question (1) it looks like you lack a WHERE clause, "SELECT * FROM members" equates to 'select all fields in the members table for all rows'. Adding a WHERE clause allows you to selectively return results. A LIMIT would give you just a subset of the rows.

I only glanced over the code (fwiw, it helps to break it down into smaller questions as there's a lot of code there), it seems questions 2 and 3 are more client-side orientated. Which browser do you use? Sometimes using a tool like Firebug (for Firefox) is helpful in quickly diagnosing style/layout problems, as it lets you edit code within the browser and renders it instantly. It saves using your favourite HTML editor and continually refreshing the browser to see all the changes you make.

piatkow

10:00 am on Dec 22, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




For question (1) it looks like you lack a WHERE clause, "SELECT * FROM members" equates to 'select all fields in the members table for all rows'. Adding a WHERE clause allows you to selectively return results. A LIMIT would give you just a subset of the rows.

From my past life as a professional DBA I would always advise against using select * as it will very likely catch you out when you make any subsequent changes to the table (and you will, even if you think at the moment it is set in stone). Always explicitly select your columns.

brotherhood of LAN

10:30 pm on Jan 1, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd agree with that, though we don't know the OP's table structure.