Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP]Drobny problem z html w echo
Forum PHP.pl > Forum > Przedszkole
bombas51
Mam taki kodzik:

  1. echo "<p><h3>".$results['nazwa']."</h3>".$results['text']."</p>";


chcę zrobić by ".$results['nazwa']." stało się nazwą hiperłącza do ".$results['id']." lecz nie potrafię próbowałem już chyba każdej kombinacji ;/
Za każdym razem wybija mi błąd..

Proszę o pomoc
tolomei
Witaj.

Jeśli chcesz utworzyć hiperłącze to zapewne powinieneś utworzyć znacznik <a href.......>.
Błąd Ci "wybija" - napisz jaki błąd.

Pozdrawiam
!*!
Jak już to:
  1. echo '<p><h3>'.$results['nazwa'].'</h3>'.$results['text'].'</p>';


A poza tym, to o co Ci chodzi? I jak błąd.
bombas51
chodzi mi o to tylko coś klamry mi się nie zgadzają:
  1. echo "<p><h3><a href="wynalazca.php?id='".$results['id']."'">".$results['nazwa']."</a></h3>".$results['tresc']."</p>";

bo wywala
  1. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/.....
!*!
Popatrz na kod który podałem wyżej. Użyj apostrofów w echo, nie będziesz mieć tego problemu, a jak koniecznie się upierasz, to przed " w kodzie html wstaw \
djgarsi
  1. echo '<p><h3><a href="wynalazca.php?id="'.$results['id'].'">"'.$results['nazwa'].'"</a></h3>"'.$results['tresc'].'"</p>';

Podstawy podstaw PHP.
tolomei
Podstawy php tak?
Twój kod także nie jest poprawny kolego smile.gif
!*!
Cytat
Cytat
echo '<p><h3><a href="wynalazca.php?id="'.$results['id'].'">"'.$results['nazwa'].'"</a></h3>"'.$results['tresc'].'"</p>';

Podstawy podstaw PHP.

Jak to mawiają młodzi... FAIL.
bombas51
Dzięki wszystkim tym co pomogli. Mam jeszcze jeden problem smile.gif


  1. $raw_results = mysql_query("SELECT * FROM wynalazki
  2. WHERE (`nazwa` LIKE '%".$query."%') OR (`wynalazca` LIKE '%".$query."%')") or die(mysql_error());


To jest zapytanie które szuka mi "wynalazków", ja chciałbym w wyszukiwarce wyświetlić również "wynalazców" którzy są w innej tabeli
Jak to skonstruować ?

wynalazcy
|id|imie_nazwisko|



Tutaj cały kod wyszukiwarki jakbybył potrzebny:

  1. <head>
  2. <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-2" />
  3. </head>
  4.  
  5. <form action="szukaj.php" method="GET">
  6. <input type="text" name="s" />
  7. <input type="submit" value="Szukaj" />
  8. </form>
  9.  
  10. <?php
  11. mysql_connect("localhost", "...", ".....") or die("Error connecting to database: ".mysql_error());
  12. /*
  13.   localhost - it's location of the mysql server, usually localhost
  14.   root - your username
  15.   third is your password
  16.  
  17.   if connection fails it will stop loading the page and display an error
  18.   */
  19.  
  20. mysql_select_db(".......l") or die(mysql_error());
  21. /* tutorial_search is the name of database we've created */
  22. ?>
  23.  
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <head>
  27. <title>Search results</title>
  28. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  29. <link rel="stylesheet" type="text/css" href="style.css"/>
  30. </head>
  31. <body>
  32. <?php
  33. $query = $_GET['s'];
  34. // gets value sent over search form
  35.  
  36. $min_length = 3;
  37. // you can set minimum length of the query if you want
  38.  
  39. if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
  40.  
  41. $query = htmlspecialchars($query);
  42. // changes characters used in html to their equivalents, for example: < to &gt;
  43.  
  44. $query = mysql_real_escape_string($query);
  45. // makes sure nobody uses SQL injection
  46.  
  47. $raw_results = mysql_query("SELECT * FROM wynalazki
  48. WHERE (`nazwa` LIKE '%".$query."%') OR (`wynalazca` LIKE '%".$query."%')") or die(mysql_error());
  49.  
  50. // * means that it selects all fields, you can also write: `id`, `title`, `text`
  51. // articles is the name of our table
  52.  
  53. // '%$query%' is what we're looking for, % means anything, for example if $query is Hello
  54. // it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
  55. // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
  56.  
  57. if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
  58.  
  59. while($results = mysql_fetch_array($raw_results)){
  60. // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
  61.  
  62.  
  63. //echo "<p><h3>".$results['title']."</h3>".$results['text']."</p>";
  64. //<a href="wynalazca.php?id='.$rekord[0].'">'.$rekord[1].'</a>
  65.  
  66. echo "<p><a href=\"".$results['id']."\">".$results['nazwa']."</a> - ".$results['wynalazca']."</p>";
  67.  
  68. // posts results gotten from database(title and text) you can also show id ($results['id'])
  69. }
  70.  
  71. }
  72. else{ // if there is no matching rows do following
  73. echo "No results";
  74. }
  75.  
  76. }
  77. else{ // if query length is less than minimum
  78. echo "Minimum length is ".$min_length;
  79. }
  80. ?>
  81. </body>
  82. </html>


dzięki za poprzednie odpowiedzi
krzysiekk
zakladajac ze tablica wynalazcow wyglada tak

tablica wynalazcy
id imie_nazwisko

i wynlazkow tak
tablica wynalazki
id wynalazca_id wynalazek


to zapytanie można tak napisać
SELECT * FROM wynalazki INNER JOIN wynalazcy ON wynalazki.wynalazca_id = wynalazcy.id;

To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.