[Help] If-чета и else-чета

ivowe3

Wiki
Joined
Apr 1, 2009
Messages
1,220
Reaction score
1,281
Здравейте,
Този код работи, но когато му сложа If не засича резултатите от базата данни.
PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
   while ($row = mysql_fetch_assoc($our))

   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$row[raz]<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
	<td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
	</tr>
</table>";
}

?>

Не работещия изглежда така: Някой вижда ли грешката?

PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
while ($row = mysql_fetch_assoc($our))

if($row[raz] == 1){ $raza ='HDTV';}
else{$raza =$row[raz];}

   
   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
 </tr>
</table>";
}

?>
 
PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
while ($row = mysql_fetch_assoc($our))

if($row[raz] == 1){$raza ='HDTV';}
else{$raza = $row['raz'];}

   
   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
    <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
    </tr>
</table>";
}

?>

Грешката ти беше ето тук:
if($row[raz] == 1){ $raza ='HDTV';}
else{$raza =$row[raz];}
Поправен:
if($row[raz] == 1){$raza ='HDTV';}
else{$raza = $row['raz'];}
 
Last edited:
опитай така

PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
while ($row = mysql_fetch_assoc($our))

if($row[raz] == 1){ $raza ='HDTV';}
else{$raza =$row['raz'];}

   
   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
 </tr>
</table>";
}

?>
 
  • Like
Reactions: ivowe3
опитай така

PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
while ($row = mysql_fetch_assoc($our))

if($row[raz] == 1){ $raza ='HDTV';}
else{$raza =$row['raz'];}

   
   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
 </tr>
</table>";
}

?>

Благодаря, но не се получи.
 
Виш дали колоната "raz" в базата данни се пише точно така понеже в твоя случай големите и малките букви имат значение.
 
  • Like
Reactions: ivowe3
Точно така се пише.

Когато е без if скрипта работи перфектно, но когато сложа if нещата се оплескват.

Искам да попитам и за защитата. Как да защитя заявките...
 
Last edited:
Извинявам се за двойният пост ако искате мога да ви дам и останалата част от скрипта. HTML-то, но не мисля, че ще ви потрябва.
 
PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
while ($row = mysql_fetch_assoc($our))

if($row['raz'] == 1){ $raza ='HDTV';}
else{$raza =$row['raz'];}

   
   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
 </tr>
</table>";
}

?>
Изпуснал си двете кавички във if-a така трябва да работи.
 
Last edited:
  • Like
Reactions: ivowe3
PHP:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = mysql_escape_string($_POST["name"]);
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   
   $our = mysql_query("SELECT * FROM movie where raz like '%".$raz."%' AND janr1 like '%".$cat."%' or janr2 like '%".$cat."%' or janr3 like '%".$cat."%' AND name like '%".$name."%' ORDER BY id DESC");
while ($row = mysql_fetch_assoc($our))

if($row['raz'] == 1){ $raza ='HDTV';}
else{$raza =$row['raz'];}

   
   echo "<table align=center border=1  width=90%>
<tr>
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td>
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>, 
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>, 
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>, 
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>, 
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td>
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td>
 </tr>
</table>";
}

?>
Изпуснал си двете кавички във if-a така трябва да работи.

И така не работи. Някакви други идеи???
 
PHP:
<?php 
include("config.php"); 
if(isset($_POST['submit'])) { 
    
   $name = mysql_escape_string($_POST['name']); 
   $raz = $_POST['raz']; 
   $cat = $_POST['cat']; 
   
    
   $our = mysql_query("SELECT * FROM movie where raz like ".$raz." AND janr1 like ".$cat." or janr2 like ".$cat." or janr3 like ".$cat." AND name like ".$name." ORDER BY id DESC"); 
while ($row = mysql_fetch_assoc($our)) 

if($row['raz'] == 1){ $raza ='HDTV';}     
   echo "<table align=center border=1  width=90%> 
<tr> 
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td> 
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>,  
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>,  
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>,  
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>,  
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td> 
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td> 
 </tr> 
</table>";
else{$raza = $row['raz'];}  
   echo "<table align=center border=1  width=90%> 
<tr> 
    <td width=50%><b>[</b>$raza<b>]</b>$row[name]</td> 
    <td width=30%><b>[</b><a href=$row[link1]>LINK 1</a><b>]</b>,  
<b>[</b><a href=$row[link2]>LINK 2</a><b>]</b>,  
<b>[</b><a href=$row[link3]>LINK 3</a><b>]</b>,  
<b>[</b><a href=$row[link4]>LINK 4</a><b>]</b>,  
<b>[</b><a href=$row[link5]>LINK 5</a><b>]</b></td> 
 <td width=20%>$row[janr1], $row[janr2], $row[janr3]</td> 
 </tr> 
</table>";
} 

?>
Я провери така ще го бъде ли ?
 
  • Like
Reactions: ivowe3
PHP:
else{$raza = $row['raz'];}

Parse error: parse error on line 68

ПП: не разглеждайте само if-четата може да идва от другаде тази грешка.
ПП2: грешката след като му сложа if-че е, че не излизат резултатите от базата данни
 
Last edited:
  • Like
Reactions: zombiehell
пак така.... Parse error: parse error on line 68
 
Code:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = $_POST['name'];
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   $our = mysql_query("SELECT * FROM movie where raz like '%$raz%' AND janr1 like '%$cat%' or janr2 like '%$cat%' or janr3 like '%$cat%' AND name like '%$name%' ORDER BY id DESC");
  
	while ($row = mysql_fetch_assoc($our)) {
	if($row[raz] == 1){ $raz = "HDTV"; }
		else { $raz = $row[raz]; }
echo "
<table align='center' border='1'  width='90%'>
	<tr>
		<td width='50%'><b>[</b>$row[raz]<b>]</b>$row[name]</td>
		<td width='30%'><b>[</b><a href='$row[link1]'>LINK 1</a><b>]</b>, 
			<b>[</b><a href='$row[link2]'>LINK 2</a><b>]</b>, 
			<b>[</b><a href='$row[link3]'>LINK 3</a><b>]</b>, 
			<b>[</b><a href='$row[link4]'>LINK 4</a><b>]</b>, 
			<b>[</b><a href='$row[link5]'>LINK 5</a><b>]</b></td>
		<td width='20%'>$row[janr1], $row[janr2], $row[janr3]</td>
    </tr>
</table>";
}

}
?>
 
  • Like
Reactions: ivowe3
Code:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = $_POST['name'];
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   $our = mysql_query("SELECT * FROM movie where raz like '%$raz%' AND janr1 like '%$cat%' or janr2 like '%$cat%' or janr3 like '%$cat%' AND name like '%$name%' ORDER BY id DESC");
  
	while ($row = mysql_fetch_assoc($our)) {
	if($row[raz] == 1){ $raz = "HDTV"; }
		else { $raz = $row[raz]; }
echo "
<table align='center' border='1'  width='90%'>
	<tr>
		<td width='50%'><b>[</b>$row[raz]<b>]</b>$row[name]</td>
		<td width='30%'><b>[</b><a href='$row[link1]'>LINK 1</a><b>]</b>, 
			<b>[</b><a href='$row[link2]'>LINK 2</a><b>]</b>, 
			<b>[</b><a href='$row[link3]'>LINK 3</a><b>]</b>, 
			<b>[</b><a href='$row[link4]'>LINK 4</a><b>]</b>, 
			<b>[</b><a href='$row[link5]'>LINK 5</a><b>]</b></td>
		<td width='20%'>$row[janr1], $row[janr2], $row[janr3]</td>
    </tr>
</table>";
}

}
?>

Здравей,

С риск да те обидя, в кода няма грам смисъл относно if-а, защото след това си сложил в echo $row[raz] което няма да помогне особено.
 
Бях копирал първия код и него променях виж така

Code:
<?php
include("config.php");
if(isset($_POST['submit'])) {
   
   $name = $_POST['name'];
   $raz = $_POST['raz'];
   $cat = $_POST['cat'];
  
   $our = mysql_query("SELECT * FROM movie where raz like '%$raz%' AND janr1 like '%$cat%' or janr2 like '%$cat%' or janr3 like '%$cat%' AND name like '%$name%' ORDER BY id DESC");
  
	while ($row = mysql_fetch_assoc($our)) {
	if($row[raz] == 1){ $raza = "HDTV"; }
		else { $raz = $row[raz]; }
echo "
<table align='center' border='1'  width='90%'>
	<tr>
		<td width='50%'><b>[</b>$raza<b>]</b>$row[name]</td>
		<td width='30%'><b>[</b><a href='$row[link1]'>LINK 1</a><b>]</b>, 
			<b>[</b><a href='$row[link2]'>LINK 2</a><b>]</b>, 
			<b>[</b><a href='$row[link3]'>LINK 3</a><b>]</b>, 
			<b>[</b><a href='$row[link4]'>LINK 4</a><b>]</b>, 
			<b>[</b><a href='$row[link5]'>LINK 5</a><b>]</b></td>
		<td width='20%'>$row[janr1], $row[janr2], $row[janr3]</td>
    </tr>
</table>";
}

}
?>
 
  • Like
Reactions: ivowe3
Проблемът вече е решен с помоща на Damian и XTYLING

XTYLING помогна за if-овете
Damian за останалото.
 
  • Like
Reactions: zombiehell