I have a database which I call datenbank in this example... In this database I have a table called "artikel".. I now have a number and want to search my table "artikel" in the column "idartikel" for this number; Once I found the right row I want to compare the entry of another column called kategorie_idkategorie of this row but of another column with a certain value;
To do so I start connecting to my database
error_reporting(E_ALL);
define ( 'MYSQL_HOST', 'localhost' );
define ( 'MYSQL_BENUTZER', 'root' );
define ( 'MYSQL_KENNWORT', '' );
define ( 'MYSQL_DATENBANK', 'datenbank' );
$db_link = mysqli_connect (
MYSQL_HOST,
MYSQL_BENUTZER,
MYSQL_KENNWORT,
MYSQL_DATENBANK
);
if ($db_link === False) {
die("<p> Error </p>");
}
?>
Diese connection works; Now I want to search for my numer, in this case 55065 in the table artikel and the column idartikel; Once I found the row I want the entry of the column kategorie_idkategorie and compare it to the value 1592
<?php
require_once ('configdatenbank.php');
$id=55065; //Diese Nummer möchte ich in meiner Tabelle artikel suchen
$wert1 = 1592;
$sql = "SELECT kategorie_idkategorie FROM artikel WHERE idartikel=55065";
$query = mysql_query($sql);
$row = mysql_fetch_row($query);
if($row['kategorie_idkategorie'] == $wert1){
echo 'equal';
}else{
echo 'not equal';
}
?>
For a better understanding I made a screenshot of the entry of the table;
http://www.bilder-upload.eu/show.php?file=bed499-1446912607.png
As you see there is the entry where the column idartikel has the value 55065; Now I want to check if this row has the value 1592 in the colummn kategorie_idkategorie, which is obviously true; So I should get the message "equal";
However I get several errors when doing so and also get the message "not equal"
If you look at the database you see three different parts of each column: Funktion, Null and Wert; Is it the problem that I point on the column in general and not specifically on the "wert" part of the column?
Or what is the problem in this case?
Many thanks!! :)
Edit: My new version...But it's still not working
<?php
require_once ('configdatenbank.php');
$id=55065;
$wert1 = 1592;
// MySQL-Query zum holen des wertes aus der DB
$sql = "SELECT kategorie_idkategorie FROM artikel WHERE idartikel=55065";
$query = mysqli_query($sql);
$row = mysqli_fetch_assoc($query);
if($row['kategorie_idkategorie'] == $wert1){
echo 'werte sind gleich';
}else{
echo 'werte sind nicht gleich';
}
?>