Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with 'ELSE' statement

Status
Not open for further replies.

igolo

IS-IT--Management
Jan 16, 2002
63
US
The following code searches a database for a store location, then returns the IP info. How do I get the code to ask if I would like to enter a new location only if the search location is not in the database?
I have the form (addstor.php) that will allow me to add a new location.

<?php
if ($searchstring)
{
$sql=&quot;SELECT * FROM StorIPScheme WHERE $searchtype LIKE '%$searchstring%' ORDER BY StoreName ASC&quot;;
$db = mysql_connect(&quot;-------&quot;, &quot;mforney&quot;, &quot;-------&quot;);
mysql_select_db(&quot;CalicoStores&quot;,$db);
$result = mysql_query($sql,$db);
echo &quot;<TABLE BORDER=2>&quot;;
echo&quot;<TR><TD><B>Store Number</B><TD><B>Store Name</B><TD><B>Remote IP</B><TD><B>Remote WAN</B>
<TD><B>Default Gateway</B><TD><B>DLCI#</B></TR>&quot;;
while($myrow = mysql_fetch_array($result)) {
echo &quot;<TR><TD>&quot;.$myrow[&quot;StoreNo&quot;].&quot;<TD>&quot;.$myrow[&quot;StoreName&quot;].&quot;<TD>&quot;.$myrow[&quot;RemoteIP&quot;].
&quot;<TD>&quot;.$myrow[&quot;RemoteWAN&quot;].&quot;<TD>&quot;.$myrow[&quot;Gateway&quot;].&quot;<TD>&quot;.$myrow[&quot;DLCI_No&quot;];
echo &quot;<TD><a href=\&quot;view1.php?id=&quot;.$myrow[&quot;id&quot;].&quot;\&quot;>View</a>&quot;;
}
echo &quot;</TABLE>&quot;;
}
?>
 
<?php
if ($searchstring)
{
$sql=&quot;SELECT * FROM StorIPScheme WHERE $searchtype LIKE '%$searchstring%' ORDER BY StoreName ASC&quot;;
$db = mysql_connect(&quot;-------&quot;, &quot;mforney&quot;, &quot;-------&quot;);
mysql_select_db(&quot;CalicoStores&quot;,$db);
$result = mysql_query($sql,$db);
echo &quot;<TABLE BORDER=2>&quot;;
echo&quot;<TR><TD><B>Store Number</B><TD><B>Store Name</B><TD><B>Remote IP</B><TD><B>Remote WAN</B>
<TD><B>Default Gateway</B><TD><B>DLCI#</B></TR>&quot;;
if ($myrow = mysql_fetch_array($result)) {
echo &quot;<TR><TD>&quot;.$myrow[&quot;StoreNo&quot;].&quot;<TD>&quot;.$myrow[&quot;StoreName&quot;].&quot;<TD>&quot;.$myrow[&quot;RemoteIP&quot;].
&quot;<TD>&quot;.$myrow[&quot;RemoteWAN&quot;].&quot;<TD>&quot;.$myrow[&quot;Gateway&quot;].&quot;<TD>&quot;.$myrow[&quot;DLCI_No&quot;];
echo &quot;<TD><a href=\&quot;view1.php?id=&quot;.$myrow[&quot;id&quot;].&quot;\&quot;>View</a>&quot;;
while($myrow = mysql_fetch_array($result)) {
echo &quot;<TR><TD>&quot;.$myrow[&quot;StoreNo&quot;].&quot;<TD>&quot;.$myrow[&quot;StoreName&quot;].&quot;<TD>&quot;.$myrow[&quot;RemoteIP&quot;].
&quot;<TD>&quot;.$myrow[&quot;RemoteWAN&quot;].&quot;<TD>&quot;.$myrow[&quot;Gateway&quot;].&quot;<TD>&quot;.$myrow[&quot;DLCI_No&quot;];
echo &quot;<TD><a href=\&quot;view1.php?id=&quot;.$myrow[&quot;id&quot;].&quot;\&quot;>View</a>&quot;;
}
} else {
_____________past add form here____________-
}
echo &quot;</TABLE>&quot;;
}
?>

Just hacked away, but the attempt should be clear. cu, Sascha
 
Or you could use the mysql_num_rows($result) to see if the query returned anything.
Like this
<?php
if ($searchstring)
{
$sql=&quot;SELECT * FROM StorIPScheme WHERE $searchtype LIKE '%$searchstring%' ORDER BY StoreName ASC&quot;;
$db = mysql_connect(&quot;-------&quot;, &quot;mforney&quot;, &quot;-------&quot;);
mysql_select_db(&quot;CalicoStores&quot;,$db);
$result = mysql_query($sql,$db);
echo &quot;<TABLE BORDER=2>&quot;;
echo&quot;<TR><TD><B>Store Number</B><TD><B>Store Name</B><TD><B>Remote IP</B><TD><B>Remote WAN</B>
<TD><B>Default Gateway</B><TD><B>DLCI#</B></TR>&quot;;
if (mysql_num_rows($result) > 0)
{
while($myrow = mysql_fetch_array($result)) {
echo &quot;<TR><TD>&quot;.$myrow[&quot;StoreNo&quot;].&quot;<TD>&quot;.$myrow[&quot;StoreName&quot;].&quot;<TD>&quot;.$myrow[&quot;RemoteIP&quot;].
&quot;<TD>&quot;.$myrow[&quot;RemoteWAN&quot;].&quot;<TD>&quot;.$myrow[&quot;Gateway&quot;].&quot;<TD>&quot;.$myrow[&quot;DLCI_No&quot;];
echo &quot;<TD><a href=\&quot;view1.php?id=&quot;.$myrow[&quot;id&quot;].&quot;\&quot;>View</a>&quot;;
}
}
else
{
echo &quot;Form&quot;;
}
echo &quot;</TABLE>&quot;;
}
?> //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top