mysql_connect('localhost','user','password'); mysql_select_db('news'); // החלף את השם של בסיס הנתונים בשם שאתה קבעת $result = mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC"); ?> <dl> <?php // הצגת הכתבות while ($row=mysql_fetch_assoc($result)) { %>
תיקון לקוד הוספת חדשות שעובד לא יודע איך אצלכם, אבל אצלי קוד הוספת החדשות לא עבד. מה שכן עובד זה הקוד הבא:
<?php header('Content-Type: text/html; charset=windows-1255'); if (!isset($_POST['submit'])) //אם לא נשלח הטופס { header("location: add_news_form.html"); //הפניה לטופס להזנת נתונים } else { //הצבת משתנים $subject = $_POST['subject']; $content = $_POST['content']; echo ($subject . " :ידיעה<br>"); echo ($content . " :תוכן ידיעה<br>");
//התחברות לבסיס נתונים $password="baklawa"; //שוב,4 המשתנים הנ"ל משתנים בהתאם לתוכנית! $user="me"; $dbhost = "localhost"; $dbname = "my_db";
$con=@mysql_connect($dbhost,$user,$password); //or die("ERROR: ".mysql_error()); @mysql_select_db($dbname) or die("ERROR: ".mysql_error());
//הכנסת נתונים mysql_query("SET NAMES 'hebrew'"); //תוספת לצורך המרת הנתונים לעברית @mysql_query("INSERT INTO test (subject, content) VALUES('$subject', '$content') ",$con) or die(mysql_error());
4 תשובות
תיקון לקוד של תצוגת חדשות
<?php
mysql_connect('localhost','user','password');
mysql_select_db('news'); // החלף את השם של בסיס הנתונים בשם שאתה קבעת
$result = mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC");
?>
<dl>
<?php
// הצגת הכתבות
while ($row=mysql_fetch_assoc($result)) { %>
<dt><?php echo $row['subject']; ?></dt>
<dd><?php echo $row['content']; ?></dd>
<?php } ?>
</dl>
קוד תצוגת חדשות לא עובד בשני המקרים
הוספת חדשות עובדת לי בסדר גמור, אבל הצפייה לא עובדת לא בגירסא המקורית ולא במתוקנת. מישהו יכול לעזור בנושא?
תיקון לקוד התצוגה שבאמת עובד!
<?php
header('Content-Type: text/html; charset=windows-1255');
$host="localhost"; //!כול 4 ההגדרות הנ"ל צריכות להיות מותאמות אישית
$user="user_name";
$password="your_password";
$db="db_name";
$con=@mysql_connect($host,$user,$password);
@mysql_select_db($db);
$sqlquery="SELECT * FROM test";
mysql_query("SET NAMES 'hebrew'"); //תוספת לצורך המרת הנתונים מהמסד לעברית
$theresult=@mysql_query($sqlquery,$con);
?>
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=windows-1255">
</head>
<body dir="rtl">
<table border="1" width="25%">
<tr>
<td align="center"><b>#</b></td>
<td align="center"><b>נושא</b></td>
<td align="center"><b>תוכן</b></td>
</tr>
<?
while ($recordeset=@mysql_fetch_array($theresult))
{
echo "<tr>";
echo "<td><center>".$recordeset["id"]."</center></td>";
echo "<td><center>".$recordeset["subject"]."</center></td>";
echo "<td><center>".$recordeset["content"]."</center></td>";
echo "</tr>";
}
?>
</table>
<?php mysql_close($con);?>
</body>
</html>
לי זה עבד, בהצלחה.
שחר כהן
תיקון לקוד הוספת חדשות שעובד
לא יודע איך אצלכם, אבל אצלי קוד הוספת החדשות לא עבד. מה שכן עובד זה הקוד הבא:
<?php
header('Content-Type: text/html; charset=windows-1255');
if (!isset($_POST['submit'])) //אם לא נשלח הטופס
{
header("location: add_news_form.html"); //הפניה לטופס להזנת נתונים
}
else
{
//הצבת משתנים
$subject = $_POST['subject'];
$content = $_POST['content'];
echo ($subject . " :ידיעה<br>");
echo ($content . " :תוכן ידיעה<br>");
//התחברות לבסיס נתונים
$password="baklawa"; //שוב,4 המשתנים הנ"ל משתנים בהתאם לתוכנית!
$user="me";
$dbhost = "localhost";
$dbname = "my_db";
$con=@mysql_connect($dbhost,$user,$password); //or die("ERROR: ".mysql_error());
@mysql_select_db($dbname) or die("ERROR: ".mysql_error());
//הכנסת נתונים
mysql_query("SET NAMES 'hebrew'"); //תוספת לצורך המרת הנתונים לעברית
@mysql_query("INSERT INTO test (subject, content) VALUES('$subject', '$content') ",$con) or die(mysql_error());
echo("הידיעה נוספה בהצלחה לבסיס הנתונים");
}
?>
,שחקו אותה. מעניין אם אצלכם זה יעבוד, מוזמנים לכתוב כאן
שחר כהן