26. februar 2002 - 12:56
Der er
6 kommentarer og 1 løsning
skrive tekst hvis ingen poster
Er der en som kan hjælpe mig med at lave den her kode om så den skriver en tekst hvis der ikke er nogen poster som den kan hente? koden: -------------------------------------------------------- <? session_start(); echo "<body bgcolor='#47525F' link='#CCCCCC' vlink='#CCCCCC' alink='#CCCCCC'><BR><center><font face='tahoma' color='#c9c9c9' size='5'>Dine kontakter.....</font></center>"; mysql_connect("localhost","djsaw","pipsyl"); mysql_select_db("djsaw"); $sql = "SELECT nick FROM bruger WHERE nick='$brugernavn'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); if ($row){ if ($brugernavn){ mysql_connect("localhost","djsaw","pipsyl"); mysql_select_db("kontakt");$result = mysql_query("select * from kontakt WHERE nick='$brugernavn' ORDER BY fornavn ASC"); while ($row = mysql_fetch_array($result)) echo " <BR> <div align='center'> <table bgcolor='black' cellpadding=0 cellspacing=1 width='90%'> <tr> <td> <table bgcolor='#8098B0'width='100%'> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Fornavn:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[fornavn]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Efternavn:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[efternavn]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Adresse:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[adresse]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Nummer:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[nummer]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Postnummer:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[postnummer]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>By:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[byen]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Email:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[email]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Mobil:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[mobil]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Telefon:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[tlf]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Icq:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[icq]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Land:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[land]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Beskrivelse:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[beskrivelse] </b></font></td> </tr> </table> <table width='100%' bgcolor='#8098B0'> <tr> <td> </td> </tr> </table> <table width='100%' bgcolor='#8098B0'> <tr> <td> <form method=POST action=send_mail.php> <div align='center'> <input type=hidden name='fornavn22' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: Mail ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=send_sms.php> <div align='center'> <input type=hidden name='fornavn' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: SMS ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=send_icq.php> <div align='center'> <input type=hidden name='fornavn' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: ICQ ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=inaktiv.php> <div align='center'> <input type=hidden name='fornavn' value=$row[fornavn]> <input type=hidden name='efternavn' value=$row[efternavn]> <input type=hidden name='adresse' value=$row[adresse]> <input type=hidden name='nummer' value=$row[nummer]> <input type=hidden name='postnummer' value=$row[postnummer]> <input type=hidden name='by' value=$row[byen]> <input type=hidden name='email' value=$row[email]> <input type=hidden name='mobil' value=$row[mobil]> <input type=hidden name='telefon' value=$row[tlf]> <input type=hidden name='icq' value=$row[icq]> <input type=hidden name='land' value=$row[land]> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: Ret ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=del_kontakt.php onSubmit=\"return confirm('Er du sikker på vil slette $row[fornavn] fra din kontakliste?');\"> <div align='center'> <input type=hidden name='fornavn' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value='$row[beskrivelse]'> <input type=SUBMIT value=':: Slet ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> </tr> </table> </td> </tr> </table> </div> <div align='center'><BR> </div> <BR> "; } else { echo "<font face='tahoma' color='#c9c9c9' size='4'><center><BR>De er ikke logget ind....<BR>Gå til <a href='login.php' target='main'>Login</a> eller opret en profil <a href='add.php' target='main'>HER</a></center></font>"; } } ?> -----------------------------------------------------
Annonceindlæg fra Infor
26. februar 2002 - 12:59
#1
Du kan jo bare tjekke antallet af poster med mysql_num_rows($result); Hvis mysql_num_rows returnerer 0 er de ingen poster! $num = mysql_num_rows($result); If ($num==0) { print "Ingen poster"; }
26. februar 2002 - 13:00
#2
Inden du fyrer din while løkke af, så undersøg om der overhovedet er poster i resultatet.... F.eks. mysql_select_db("kontakt"); $result = mysql_query("select * from kontakt if (mysql_num_rows($result)>0) { WHERE nick='$brugernavn' ORDER BY fornavn ASC"); while ($row = mysql_fetch_array($result)) echo " <BR> <div align='center'> .. .. .. } else { echo("Din tekst her!"); }
26. februar 2002 - 13:09
#3
Kan en af jer ikke sætte det ind i den kode jeg smed ind? den skal checke om der er nogen poster ud fra nick altså ("select * from kontakt where nick='brugernavn'") eller noget i den stil...
26. februar 2002 - 13:22
#4
er det iorden hvis jeg lige ændre lidt i din kode så den blir lidt mere overskuelig???
26. februar 2002 - 13:25
#5
selvfølgeligt er det det... Er meget ny så er ikke den bedste endnu...
26. februar 2002 - 17:37
#6
Her er koden så... jeg har ikke lige testet den men burde at virke... men hvis det ikke er tilfældet så skriv lige igen! ---------------------------------------------------- <? session_start(); if ($brugernavn) { print "<body bgcolor='#47525F' link='#CCCCCC' vlink='#CCCCCC' alink='#CCCCCC'>"; print "<br>"; print "<center>"; print "<font face='tahoma' color='#c9c9c9' size='5'>Dine kontakter.....</font>"; print "</center>"; mysql_connect("localhost","djsaw","pipsyl"); mysql_select_db("djsaw"); $query = mysql_query("SELECT nick FROM bruger WHERE nick='$brugernavn'"); $row = mysql_fetch_array($query); if(mysql_num_rows($query) < 1) { print "Du har ikke nogen konkakter"; } else { $result = mysql_query("select * from kontakt WHERE nick='$brugernavn' ORDER BY fornavn ASC"); while ($row = mysql_fetch_array($result)) echo " <BR> <div align='center'> <table bgcolor='black' cellpadding=0 cellspacing=1 width='90%'> <tr> <td> <table bgcolor='#8098B0'width='100%'> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Fornavn:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[fornavn]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Efternavn:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[efternavn]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Adresse:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[adresse]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Nummer:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[nummer]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Postnummer:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[postnummer]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>By:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[byen]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Email:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[email]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Mobil:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[mobil]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Telefon:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[tlf]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Icq:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[icq]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Land:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[land]</b></font></td> </tr> <tr> <td width='16%'> <div align='right'><font color='#000000'><b><font face='tahoma' size='4'>Beskrivelse:</font></b></font></div> </td> <td width='2%'> </td> <td width='82%'><font face='tahoma' color='#595959' size='4'><b>$row[beskrivelse] </b></font></td> </tr> </table> <table width='100%' bgcolor='#8098B0'> <tr> <td> </td> </tr> </table> <table width='100%' bgcolor='#8098B0'> <tr> <td> <form method=POST action=send_mail.php> <div align='center'> <input type=hidden name='fornavn22' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: Mail ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=send_sms.php> <div align='center'> <input type=hidden name='fornavn' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: SMS ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=send_icq.php> <div align='center'> <input type=hidden name='fornavn' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: ICQ ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=inaktiv.php> <div align='center'> <input type=hidden name='fornavn' value=$row[fornavn]> <input type=hidden name='efternavn' value=$row[efternavn]> <input type=hidden name='adresse' value=$row[adresse]> <input type=hidden name='nummer' value=$row[nummer]> <input type=hidden name='postnummer' value=$row[postnummer]> <input type=hidden name='by' value=$row[byen]> <input type=hidden name='email' value=$row[email]> <input type=hidden name='mobil' value=$row[mobil]> <input type=hidden name='telefon' value=$row[tlf]> <input type=hidden name='icq' value=$row[icq]> <input type=hidden name='land' value=$row[land]> <input type=hidden name='beskrivelse' value=$row[beskrivelse]> <input type=SUBMIT value=':: Ret ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> <td width='20%'> <form method=POST action=del_kontakt.php onSubmit=\"return confirm('Er du sikker på vil slette $row[fornavn] fra din kontakliste?');\"> <div align='center'> <input type=hidden name='fornavn' value='$row[fornavn]'> <input type=hidden name='efternavn' value='$row[efternavn]'> <input type=hidden name='adresse' value='$row[adresse]'> <input type=hidden name='nummer' value='$row[nummer]'> <input type=hidden name='postnummer' value='$row[postnummer]'> <input type=hidden name='by' value='$row[byen]'> <input type=hidden name='email' value='$row[email]'> <input type=hidden name='mobil' value='$row[mobil]'> <input type=hidden name='telefon' value='$row[tlf]'> <input type=hidden name='icq' value='$row[icq]'> <input type=hidden name='land' value='$row[land]'> <input type=hidden name='beskrivelse' value='$row[beskrivelse]'> <input type=SUBMIT value=':: Slet ::' style='background-color: #AAB8C0; border: 1 solid #000000' name='SUBMIT'> </div> </form> </td> </tr> </table> </td> </tr> </table> </div> <div align='center'><BR> </div> <BR> "; } } else { print "<font face='tahoma' color='#c9c9c9' size='4'>"; print "<center>"; print "<br>"; print "De er ikke logget ind..."; print "<br>"; print "Gå til <a href='login.php' target='main'>Login</a>"; print "eller opret en profil <a href='add.php' target='main'>HER</a></center></font>"; } ?>
26. februar 2002 - 17:39
#7
jeg har lavet en stavefejl... det hedder jo kontakter...
Vi tilbyder markedets bedste kurser inden for webudvikling