prudens Posted March 2, 2008 Share Posted March 2, 2008 MYSQL 4.xxx $user_id = 1582; $query2 = "SELECT * FROM books WHERE authors HAVING $user_id"; $results2 = mysql_query($query2); $n = 1; echo "Books you are author of: "; if (!$results2) { echo "None<br/>"; } while ( $row2 = mysql_fetch_array($results2) ) { echo "(". $n .")" . "{$row2['title']}" . "<br/>"; $n++; } //close db for others mysql_close($conn); authors {varstring(100)} {1582,5832,2920} Basically, I want to find * that contains "1582" in the author column... Is "FROM author HAVING $user_id" correct???? doesn't work!!! Quote Link to comment https://forums.phpfreaks.com/topic/93934-help/ Share on other sites More sharing options...
prudens Posted March 2, 2008 Author Share Posted March 2, 2008 so basically I just want to search my table for all rows that contain 1582 in "authors," and if there is none, I want to echo "None."; Quote Link to comment https://forums.phpfreaks.com/topic/93934-help/#findComment-481292 Share on other sites More sharing options...
prudens Posted March 2, 2008 Author Share Posted March 2, 2008 -- phpMyAdmin SQL Dump -- version 2.6.4-pl2 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Mar 02, 2008 at 01:51 AM -- Server version: 4.1.11 -- PHP Version: 4.3.10-22 -- -- Database: `gg` -- -- -------------------------------------------------------- -- -- Table structure for table `studentgov_legislation` -- CREATE TABLE `books` ( `id` int(11) NOT NULL auto_increment, `title` varchar(100) NOT NULL default '', `authors` varchar(100) NOT NULL default '', `sponsors` varchar(100) NOT NULL default '', `date` int(11) NOT NULL default '0', `type` tinyint(4) NOT NULL default '0', `body` text NOT NULL, `status` tinyint(4) NOT NULL default '0', `organization` varchar(50) NOT NULL default '', `school` varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `books` -- INSERT INTO `books` VALUES (1, 'The ASG Sustainability and Campus Environment Senate Committee Creation Act of 2008', '20600205,20607137', '1582,20600205', 3012008, 1, 'Whereas: The University of Arkansas has committed itself to the endeavor of promoting an environmentally friendly campus; and\r\n\r\nWhereas: The Associated Student Government should also take a proactive role in the task of creating the most environmentally friendly campus as possible; and\r\n\r\nWhereas: Currently all legislation concerning campus recycling or sustainability is directed to no certain Senate committee, and that such a committee created for the purpose of reviewing this legislation would be helpful; and\r\n\r\nWhereas: Having a Senate standing committee created to address just these issues would create an atmosphere that is conducive towards the creation of legislation that would help promote an environmentally friendly campus; and\r\n\r\nWhereas: The creation of a ASG Senate standing committee concerning recycling and sustainability issues will help promote a dialogue between students, administration, and facilities management; and\r\n\r\nWhereas: The creation of this committee will be a step in the right direction concerning these issues; then\r\n\r\nBe It Therefore Amended: That Article II of the ASG Constitution, Section 22- “Sustainability and Campus Environment Committee”, parts (A), (B), and (C) be added to read as:\r\n\r\n “(A) The Sustainability and Campus Environment Committee shall be responsible for addressing, to the fullest extent of its authority, issues of recycling and sustainability efforts, and the general campus environment at University of Arkansas.”\r\n\r\n “(B) The Sustainability and Campus Environment Committee in consultation with the ASG Secretary shall to the fullest extent of its authority, help promote issues concerning the purpose of its establishment via the campus press and the UA Administration and UA Facilities Management.”\r\n\r\n “(C) The Sustainability and Campus Environment Committee Chair shall be the presiding officer of the committee and shall coordinate the committee’s meetings.”\r\n\r\nBe It Therefore Enacted: That Title II of the ASG Code, Section 18- “Sustainability and Campus Environment Committee”, parts (A), (B), and (C) be added to read as:\r\n\r\n “(A) The Sustainability and Campus Environment Committee shall be responsible for examining and reviewing any proposed legislation concerning issues directed or related to recycling on campus, or University wide sustainability.”\r\n\r\n “(B) In addition to his/her duties as ASG Sustainability and Campus Environment Committee Chair, the Sustainability and Campus Environment Committee Chair shall maintain regular correspondence with the UA Administration and UA Facilities Management following or preceding each meeting of that committee.”\r\n\r\n “(C) In addition to the Sustainability and Campus Environment Committee’s responsibilities, be it also included that this committee in coordination with the ASG Executive Branch sponsor and help promote the “Recycling with the Razorbacks” program, and any other future programs concerning the issues of recycling and sustainability efforts, and the general campus environment at University of Arkansas.”\r\n\r\nBe It Further Enacted: “That all above said changes to the ASG Code shall only be enacted upon after required ASG Constitutional Amendments are passed and approved.”\r\n\r\nBe It Further Enacted: “That upon passing and approval of required ASG Constitutional Amendments, that said above changes to the ASG Code shall take effect immediately.”', 0, 'Associated Student Government', 'University of Arkansas at Fayetteville'); INSERT INTO `books` VALUES (2, 'A Resolution to Abolish Veto', '20600205,20607137', '20609552,20600205', 3012008, 1, 'Arms, and the man I sing, who, forc''d by fate,\r\nAnd haughty Juno''s unrelenting hate,\r\nExpell''d and exil''d, left the Trojan shore.\r\nLong labors, both by sea and land, he bore,\r\nAnd in the doubtful war, before he won\r\nThe Latian realm, and built the destin''d town;\r\nHis banish''d gods restor''d to rites divine,\r\nAnd settled sure succession in his line,\r\nFrom whence the race of Alban fathers come,\r\nAnd the long glories of majestic Rome.\r\nO Muse! the causes and the crimes relate;\r\nWhat goddess was provok''d, and whence her hate;\r\nFor what offense the Queen of Heav''n began\r\nTo persecute so brave, so just a man;\r\nInvolv''d his anxious life in endless cares,\r\nExpos''d to wants, and hurried into wars!\r\nCan heav''nly minds such high resentment show,\r\nOr exercise their spite in human woe?\r\nAgainst the Tiber''s mouth, but far away,\r\nAn ancient town was seated on the sea;\r\nA Tyrian colony; the people made\r\nStout for the war, and studious of their trade:\r\nCarthage the name; belov''d by Juno more\r\nThan her own Argos, or the Samian shore.\r\nHere stood her chariot; here, if Heav''n were kind,\r\nThe seat of awful empire she design''d.\r\nYet she had heard an ancient rumor fly,\r\n(Long cited by the people of the sky,)\r\nThat times to come should see the Trojan race\r\nHer Carthage ruin, and her tow''rs deface;\r\nNor thus confin''d, the yoke of sov''reign sway\r\nShould on the necks of all the nations lay.\r\nShe ponder''d this, and fear''d it was in fate;\r\nNor could forget the war she wag''d of late\r\nFor conqu''ring Greece against the Trojan state.\r\nBesides, long causes working in her mind,\r\nAnd secret seeds of envy, lay behind;\r\nDeep graven in her heart the doom remain''d\r\nOf partial Paris, and her form disdain''d;\r\nThe grace bestow''d on ravish''d Ganymed,\r\nElectra''s glories, and her injur''d bed.\r\nEach was a cause alone; and all combin''d\r\nTo kindle vengeance in her haughty mind.\r\nFor this, far distant from the Latian coast\r\nShe drove the remnants of the Trojan host;\r\nAnd sev''n long years th'' unhappy wand''ring train\r\nWere toss''d by storms, and scatter''d thro'' the main.\r\nSuch time, such toil, requir''d the Roman name,\r\nSuch length of labor for so vast a frame.\r\nNow scarce the Trojan fleet, with sails and oars,\r\nHad left behind the fair Sicilian shores,\r\nEnt''ring with cheerful shouts the wat''ry reign,\r\nAnd plowing frothy furrows in the main;\r\nWhen, lab''ring still with endless discontent,\r\nThe Queen of Heav''n did thus her fury vent:\r\n"Then am I vanquish''d? must I yield?" said she,\r\n"And must the Trojans reign in Italy?\r\nSo Fate will have it, and Jove adds his force;\r\nNor can my pow''r divert their happy course.\r\nCould angry Pallas, with revengeful spleen,\r\nThe Grecian navy burn, and drown the men?\r\nShe, for the fault of one offending foe,\r\nThe bolts of Jove himself presum''d to throw:\r\nWith whirlwinds from beneath she toss''d the ship,\r\nAnd bare expos''d the bosom of the deep;\r\nThen, as an eagle gripes the trembling game,\r\nThe wretch, yet hissing with her father''s flame,\r\nShe strongly seiz''d, and with a burning wound\r\nTransfix''d, and naked, on a rock she bound.\r\nBut I, who walk in awful state above,\r\nThe majesty of heav''n, the sister wife of Jove,\r\nFor length of years my fruitless force employ\r\nAgainst the thin remains of ruin''d Troy!\r\nWhat nations now to Juno''s pow''r will pray,\r\nOr off''rings on my slighted altars lay?"\r\nThus rag''d the goddess; and, with fury fraught.\r\nThe restless regions of the storms she sought,\r\nWhere, in a spacious cave of living stone,\r\nThe tyrant Aeolus, from his airy throne,\r\nWith pow''r imperial curbs the struggling winds,\r\nAnd sounding tempests in dark prisons binds.\r\nThis way and that th'' impatient captives tend,\r\nAnd, pressing for release, the mountains rend.\r\nHigh in his hall th'' undaunted monarch stands,\r\nAnd shakes his scepter, and their rage commands;\r\nWhich did he not, their unresisted sway\r\nWould sweep the world before them in their way;\r\nEarth, air, and seas thro'' empty space would roll,\r\nAnd heav''n would fly before the driving soul.\r\nIn fear of this, the Father of the Gods\r\nConfin''d their fury to those dark abodes,\r\nAnd lock''d ''em safe within, oppress''d with mountain loads;\r\nImpos''d a king, with arbitrary sway,\r\nTo loose their fetters, or their force allay.\r\nTo whom the suppliant queen her pray''rs address''d,\r\nAnd thus the tenor of her suit express''d:\r\n"O Aeolus! for to thee the King of Heav''n\r\nThe pow''r of tempests and of winds has giv''n;\r\nThy force alone their fury can restrain,\r\nAnd smooth the waves, or swell the troubled main-\r\nA race of wand''ring slaves, abhorr''d by me,\r\nWith prosp''rous passage cut the Tuscan sea;\r\nTo fruitful Italy their course they steer,\r\nAnd for their vanquish''d gods design new temples there.\r\nRaise all thy winds; with night involve the skies;\r\nSink or disperse my fatal enemies.\r\nTwice sev''n, the charming daughters of the main,\r\nAround my person wait, and bear my train:\r\nSucceed my wish, and second my design;\r\nThe fairest, Deiopeia, shall be thine,\r\nAnd make thee father of a happy line."\r\nTo this the god: "''T is yours, O queen, to will\r\nThe work which duty binds me to fulfil.\r\nThese airy kingdoms, and this wide command,\r\nAre all the presents of your bounteous hand:\r\nYours is my sov''reign''s grace; and, as your guest,\r\nI sit with gods at their celestial feast;\r\nRaise tempests at your pleasure, or subdue;\r\nDispose of empire, which I hold from you."\r\nHe said, and hurl''d against the mountain side\r\nHis quiv''ring spear, and all the god applied.\r\nThe raging winds rush thro'' the hollow wound,\r\nAnd dance aloft in air, and skim along the ground;\r\nThen, settling on the sea, the surges sweep,\r\nRaise liquid mountains, and disclose the deep.\r\nSouth, East, and West with mix''d confusion roar,\r\nAnd roll the foaming billows to the shore.\r\nThe cables crack; the sailors'' fearful cries\r\nAscend; and sable night involves the skies;\r\nAnd heav''n itself is ravish''d from their eyes.\r\nLoud peals of thunder from the poles ensue;\r\nThen flashing fires the transient light renew;\r\nThe face of things a frightful image bears,\r\nAnd present death in various forms appears.\r\nStruck with unusual fright, the Trojan chief,\r\nWith lifted hands and eyes, invokes relief;\r\nAnd, "Thrice and four times happy those," he cried,\r\n"That under Ilian walls before their parents died!\r\nTydides, bravest of the Grecian train!\r\nWhy could not I by that strong arm be slain,\r\nAnd lie by noble Hector on the plain,\r\nOr great Sarpedon, in those bloody fields\r\nWhere Simois rolls the bodies and the shields\r\nOf heroes, whose dismember''d hands yet bear\r\nThe dart aloft, and clench the pointed spear!"\r\nThus while the pious prince his fate bewails,\r\nFierce Boreas drove against his flying sails,\r\nAnd rent the sheets; the raging billows rise,\r\nAnd mount the tossing vessels to the skies:\r\nNor can the shiv''ring oars sustain the blow;\r\nThe galley gives her side, and turns her prow;\r\nWhile those astern, descending down the steep,\r\nThro'' gaping waves behold the boiling deep.\r\nThree ships were hurried by the southern blast,\r\nAnd on the secret shelves with fury cast.\r\nThose hidden rocks th'' Ausonian sailors knew:\r\nThey call''d them Altars, when they rose in view,\r\nAnd show''d their spacious backs above the flood.\r\nThree more fierce Eurus, in his angry mood,\r\nDash''d on the shallows of the moving sand,\r\nAnd in mid ocean left them moor''d aland.\r\nOrontes'' bark, that bore the Lycian crew,\r\n(A horrid sight!) ev''n in the hero''s view,\r\nFrom stem to stern by waves was overborne:\r\nThe trembling pilot, from his rudder torn,\r\nWas headlong hurl''d; thrice round the ship was toss''d,\r\nThen bulg''d at once, and in the deep was lost;\r\nAnd here and there above the waves were seen\r\nArms, pictures, precious goods, and floating men.\r\nThe stoutest vessel to the storm gave way,\r\nAnd suck''d thro'' loosen''d planks the rushing sea.\r\nIlioneus was her chief: Alethes old,\r\nAchates faithful, Abas young and bold,\r\nEndur''d not less; their ships, with gaping seams,\r\nAdmit the deluge of the briny streams.\r\nMeantime imperial Neptune heard the sound\r\nOf raging billows breaking on the ground.\r\nDispleas''d, and fearing for his wat''ry reign,\r\nHe rear''d his awful head above the main,\r\nSerene in majesty; then roll''d his eyes\r\nAround the space of earth, and seas, and skies.\r\nHe saw the Trojan fleet dispers''d, distress''d,\r\nBy stormy winds and wintry heav''n oppress''d.\r\nFull well the god his sister''s envy knew,\r\nAnd what her aims and what her arts pursue.\r\nHe summon''d Eurus and the western blast,\r\nAnd first an angry glance on both he cast;\r\nThen thus rebuk''d: "Audacious winds! from whence\r\nThis bold attempt, this rebel insolence?\r\nIs it for you to ravage seas and land,\r\nUnauthoriz''d by my supreme command?\r\nTo raise such mountains on the troubled main?\r\nWhom I- but first ''t is fit the billows to restrain;\r\nAnd then you shall be taught obedience to my reign.\r\nHence! to your lord my royal mandate bear-\r\nThe realms of ocean and the fields of air\r\nAre mine, not his. By fatal lot to me\r\nThe liquid empire fell, and trident of the sea.\r\nHis pow''r to hollow caverns is confin''d:\r\nThere let him reign, the jailer of the wind,\r\nWith hoarse commands his breathing subjects call,\r\nAnd boast and bluster in his empty hall."\r\nHe spoke; and, while he spoke, he smooth''d the sea,\r\nDispell''d the darkness, and restor''d the day.\r\nCymothoe, Triton, and the sea-green train\r\nOf beauteous nymphs, the daughters of the main,\r\nClear from the rocks the vessels with their hands:\r\nThe god himself with ready trident stands,\r\nAnd opes the deep, and spreads the moving sands;\r\nThen heaves them off the shoals. Where''er he guides\r\nHis finny coursers and in triumph rides,\r\nThe waves unruffle and the sea subsides.\r\nAs, when in tumults rise th'' ignoble crowd,\r\nMad are their motions, and their tongues are loud;\r\nAnd stones and brands in rattling volleys fly,\r\nAnd all the rustic arms that fury can supply:\r\nIf then some grave and pious man appear,\r\nThey hush their noise, and lend a list''ning ear;\r\nHe soothes with sober words their angry mood,\r\nAnd quenches their innate desire of blood:\r\nSo, when the Father of the Flood appears,\r\nAnd o''er the seas his sov''reign trident rears,\r\nTheir fury falls: he skims the liquid plains,\r\nHigh on his chariot, and, with loosen''d reins,\r\nMajestic moves along, and awful peace maintains.\r\nThe weary Trojans ply their shatter''d oars\r\nTo nearest land, and make the Libyan shores.\r\nWithin a long recess there lies a bay:\r\nAn island shades it from the rolling sea,\r\nAnd forms a port secure for ships to ride;\r\nBroke by the jutting land, on either side,\r\nIn double streams the briny waters glide.\r\nBetwixt two rows of rocks a sylvan scene\r\nAppears above, and groves for ever green:\r\nA grot is form''d beneath, with mossy seats,\r\nTo rest the Nereids, and exclude the heats.\r\nDown thro'' the crannies of the living walls\r\nThe crystal streams descend in murm''ring falls:\r\nNo haulsers need to bind the vessels here,\r\nNor bearded anchors; for no storms they fear.\r\nSev''n ships within this happy harbor meet,\r\nThe thin remainders of the scatter''d fleet.\r\nThe Trojans, worn with toils, and spent with woes,\r\nLeap on the welcome land, and seek their wish''d repose.\r\nFirst, good Achates, with repeated strokes\r\nOf clashing flints, their hidden fire provokes:\r\nShort flame succeeds; a bed of wither''d leaves\r\nThe dying sparkles in their fall receives:\r\nCaught into life, in fiery fumes they rise,\r\nAnd, fed with stronger food, invade the skies.\r\nThe Trojans, dropping wet, or stand around\r\nThe cheerful blaze, or lie along the ground:\r\nSome dry their corn, infected with the brine,\r\nThen grind with marbles, and prepare to dine.\r\nAeneas climbs the mountain''s airy brow,\r\nAnd takes a prospect of the seas below,\r\nIf Capys thence, or Antheus he could spy,\r\nOr see the streamers of Caicus fly.\r\nNo vessels were in view; but, on the plain,\r\nThree beamy stags command a lordly train\r\nOf branching heads: the more ignoble throng\r\nAttend their stately steps, and slowly graze along.\r\nHe stood; and, while secure they fed below,\r\nHe took the quiver and the trusty bow\r\nAchates us''d to bear: the leaders first\r\nHe laid along, and then the vulgar pierc''d;\r\nNor ceas''d his arrows, till the shady plain\r\nSev''n mighty bodies with their blood distain.\r\nFor the sev''n ships he made an equal share,\r\nAnd to the port return''d, triumphant from the war.\r\nThe jars of gen''rous wine (Acestes'' gift,\r\nWhen his Trinacrian shores the navy left)\r\nHe set abroach, and for the feast prepar''d,\r\nIn equal portions with the ven''son shar''d.\r\nThus while he dealt it round, the pious chief\r\nWith cheerful words allay''d the common grief:\r\n"Endure, and conquer! Jove will soon dispose\r\nTo future good our past and present woes.\r\nWith me, the rocks of Scylla you have tried;\r\nTh'' inhuman Cyclops and his den defied.\r\nWhat greater ills hereafter can you bear?\r\nResume your courage and dismiss your care,\r\nAn hour will come, with pleasure to relate\r\nYour sorrows past, as benefits of Fate.\r\nThro'' various hazards and events, we move\r\nTo Latium and the realms foredoom''d by Jove.\r\nCall''d to the seat (the promise of the skies)\r\nWhere Trojan kingdoms once again may rise,\r\nEndure the hardships of your present state;\r\nLive, and reserve yourselves for better fate."\r\nThese words he spoke, but spoke not from his heart;\r\nHis outward smiles conceal''d his inward smart.\r\nThe jolly crew, unmindful of the past,\r\nThe quarry share, their plenteous dinner haste.\r\nSome strip the skin; some portion out the spoil;\r\nThe limbs, yet trembling, in the caldrons boil;\r\nSome on the fire the reeking entrails broil.\r\nStretch''d on the grassy turf, at ease they dine,\r\nRestore their strength with meat, and cheer their souls with wine.\r\nTheir hunger thus appeas''d, their care attends\r\nThe doubtful fortune of their absent friends:\r\nAlternate hopes and fears their minds possess,\r\nWhether to deem ''em dead, or in distress.\r\nAbove the rest, Aeneas mourns the fate\r\nOf brave Orontes, and th'' uncertain state\r\nOf Gyas, Lycus, and of Amycus.\r\nThe day, but not their sorrows, ended thus.\r\nWhen, from aloft, almighty Jove surveys\r\nEarth, air, and shores, and navigable seas,\r\nAt length on Libyan realms he fix''d his eyes-\r\nWhom, pond''ring thus on human miseries,\r\nWhen Venus saw, she with a lowly look,\r\nNot free from tears, her heav''nly sire bespoke:\r\n"O King of Gods and Men! whose awful hand\r\nDisperses thunder on the seas and land,\r\nDisposing all with absolute command;\r\nHow could my pious son thy pow''r incense?\r\nOr what, alas! is vanish''d Troy''s offense?\r\nOur hope of Italy not only lost,\r\nOn various seas by various tempests toss''d,\r\nBut shut from ev''ry shore, and barr''d from ev''ry coast. ', 0, 'Residents'' Interhall Congress', 'University of Arkansas at Fayetteville'); INSERT INTO `books` VALUES (3, 'Random Shit', 'Nobody', 'Nobody', 0, 0, 'asdfasdfasdfsadf', 0, 'Jerkoff', 'Crap'); Quote Link to comment https://forums.phpfreaks.com/topic/93934-help/#findComment-481300 Share on other sites More sharing options...
fenway Posted March 2, 2008 Share Posted March 2, 2008 authors {varstring(100)} {1582,5832,2920} Basically, I want to find * that contains "1582" in the author column... Is "FROM author HAVING $user_id" correct???? doesn't work!!! you have a list in a single field -- that's a no-no. HAVING is not the right approach. You can probably get away with "WHERE FIND_IN_SET( authors, '$user_id' ) " simply because it's a comma. But this is poor DB design. Quote Link to comment https://forums.phpfreaks.com/topic/93934-help/#findComment-481366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.